Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 681 Bytes

implicit_call_tearoffs.md

File metadata and controls

37 lines (28 loc) · 681 Bytes

Pattern: Use of implicit .call tear off

Issue: -

Description

DO explicitly tear off .call methods from objects when assigning to a Function type. There is less magic with an explicit tear off. Future language versions may remove the implicit call tear off.

Example of incorrect code:

class Callable {
 void call() {}
}
void callIt(void Function() f) {
 f();
}

callIt(Callable());

Example of correct code:

class Callable {
 void call() {}
}
void callIt(void Function() f) {
 f();
}

callIt(Callable().call);

Further Reading