'why do we need Callable classes in dart
What is the use of callable classes in dart lang? Following is the example code available on official dart site.
class WannabeFunction {
call(String a, String b, String c) => '$a $b $c!';
}
main() {
var wf = new WannabeFunction();
var out = wf("Hi","there,","gang");
print('$out');
}
How useful is it add a call function and call it using a class instead of creating a function itself in class
Solution 1:[1]
This can be useful to make "named functions":
class _Foo {
const _Foo();
void call(int bar) {}
void named() {}
}
const foo = _Foo();
Which allows both:
foo(42);
and
foo.named();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michel Feinstein |
