What does this print?
int count = 0;
void main() {
late String msg = getValue();
print(count);
print(msg);
print(count);
}
String getValue() {
count++;
return "Hi";
}
Try it in the online Dart Playground →
[spoiler title="Solution"]
Answer:
0 Hi 1
Explanation:
Late variables with initializers use lazy evaluation – getValue() only runs when msg is first accessed, not when declared.
[/spoiler]