Please help me understand what exactly this means:
Quote from Chapter 2. A Review of the Language of Gifting
A local, top, or class variable declared as final is initialized on first use
So this is my test code:
lazyTest(msg) => print(msg);
class Printer{
Printer(msg){
print(msg);
}
final finalClassVariable = lazyTest("final class variable");
}
var globalsAreLazy = lazyTest("top-level");
var lazyInitialized = lazyTest("lazy initialized");
void main() {
final localFinal = new Printer("local final");
var initialize = lazyInitialized;
}
Conclusion:
final class variable
local final
lazy initialized
Both finalClassVariableand localFinalinitialized and just globalsAreLazyhave not been. lazyInitializedwas initialized on access as I expected.
source
share