Closed
Description
Say a class had a nullable method, i.e. an optional callback.
class Foo {
Foo([this.doSomething]);
final int Function() doSomething;
}
In order to avoid an error, I have to do a null-check on the method before executing it:
void main() {
Foo foo = Foo();
if (foo.doSomething != null) {
foo.doSomething();
}
}
But it would make the code look a lot cleaner, if this were possible:
void main() {
Foo().doSomething?(); // null-aware execution
}