type_parameter_referenced_by_static
Static members can't reference type parameters of the class.
Description
#The analyzer produces this diagnostic when a static member references a type parameter that is declared for the class. Type parameters only have meaning for instances of the class.
Example
#The following code produces this diagnostic because the static method
hasType
has a reference to the type parameter T
:
dart
class C<T> {
static bool hasType(Object o) => o is T;
}
Common fixes
#If the member can be an instance member, then remove the keyword static
:
dart
class C<T> {
bool hasType(Object o) => o is T;
}
If the member must be a static member, then make the member be generic:
dart
class C<T> {
static bool hasType<S>(Object o) => o is S;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。