Last active
December 16, 2021 09:22
-
-
Save II11II/067a3c1c05f9ee8c68e859b945a2e41f to your computer and use it in GitHub Desktop.
Lazy initialization in dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print("entry point"); | |
print(string); | |
print(string); | |
print(customClass); | |
print(customClass); | |
print("exit point"); | |
} | |
String string = () { | |
print("It initialises only once"); | |
return "Lorem ipsum"; | |
}(); | |
CustomClass customClass = () { | |
print("It initialises object only once"); | |
return CustomClass(); | |
}(); | |
class CustomClass { | |
CustomClass() { | |
print("CustomClass constructor called"); | |
} | |
@override | |
String toString() => "CustomClass"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment