generic_method_type_instantiation_on_dynamic
A method tear-off on a receiver whose type is 'dynamic' can't have type arguments.
Description
#The analyzer produces this diagnostic when an instance method is being torn
off from a receiver whose type is dynamic
, and the tear-off includes type
arguments. Because the analyzer can't know how many type parameters the
method has, or whether it has any type parameters, there's no way it can
validate that the type arguments are correct. As a result, the type
arguments aren't allowed.
Example
#The following code produces this diagnostic because the type of p
is
dynamic
and the tear-off of m
has type arguments:
void f(dynamic list) {
list.fold<int>;
}
Common fixes
#If you can use a more specific type than dynamic
, then change the type of
the receiver:
void f(List<Object> list) {
list.fold<int>;
}
If you can't use a more specific type, then remove the type arguments:
void f(dynamic list) {
list.cast;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。