hkk
hkk

Reputation: 2149

Dart equivalent of anonymous closures

Is there something similar to anonymous closures in Dart? Or is this feature unnecessary with OOP? Is there a workaround?

Thanks.

Upvotes: 1

Views: 1800

Answers (1)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76283

You can do the same thing in Dart.

For instance :

main() {
  (() => print('hello'))();
}

That said those kind of anonymous closures are almost useless because Dart has lexical scope and you have to run Dart code inside a main function.

Upvotes: 8

Related Questions