Skip to content

Instantly share code, notes, and snippets.

@kirkdrichardson
Created October 12, 2019 23:37
Show Gist options
  • Save kirkdrichardson/ab72121a4c0fe4d1a3c29697d9a108dd to your computer and use it in GitHub Desktop.
Save kirkdrichardson/ab72121a4c0fe4d1a3c29697d9a108dd to your computer and use it in GitHub Desktop.
Callable classes in Dart
// Callable classes in Dart (as of v2.5)
// See live at https://dartpad.dartlang.org/ab72121a4c0fe4d1a3c29697d9a108dd
void main() {
MyCallableClass()();
}
class MyCallableClass {
MyCallableClass() {
print('Normal constructor');
}
// Add this method and it will run if you call an instance of a class
call() {
print('Whoa! My instance is callable');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment