implicit_ call_ tearoffs
Details about the 'implicit_call_tearoffs' diagnostic produced by the Dart analyzer.
Implicit tear-off of the 'call' method.
Description
#
The analyzer produces this diagnostic when an object with a
call method is assigned to a function-typed
variable, implicitly tearing off the call method.
Example
#
The following code produces this diagnostic because an
instance of
Callable is passed to a function expecting a
Function:
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
void f() {
callIt(Callable());
}
Common fixes
#Explicitly tear off the call method:
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
void f() {
callIt(Callable().call);
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.