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;
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.