Last active
February 25, 2022 17:05
-
-
Save iAmWillShepherd/a0b1a1da0bbac7504b4064e6c5edca1b to your computer and use it in GitHub Desktop.
Lazily initialize variables in Dart using the late keyword
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() { | |
late String s = superCostlyInitializer(); // `s` is not initialized yet | |
print(s); // `s` is initialized now that it's needed | |
} | |
String superCostlyInitializer() { | |
return "A lot of work went into initializing this result"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment