extension_declares_member_of_object
Extensions can't declare members with the same name as a member declared by 'Object'.
Description
#The analyzer produces this diagnostic when an extension declaration
declares a member with the same name as a member declared in the class
Object
. Such a member can never be used because the member in Object
is
always found first.
Example
#The following code produces this diagnostic because toString
is defined
by Object
:
dart
extension E on String {
String toString() => this;
}
Common fixes
#Remove the member or rename it so that the name doesn't conflict with the
member in Object
:
dart
extension E on String {
String displayString() => this;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。