Dartisans,
We now have one of the major new language features of M1 implemented
across the board. That's right -- you can now use lazy initialization
for top-level and static variables (both final and non-final). This
means that the restriction that used to force the initialization
expression for such a variable to be a compile-time constant is no
more. You can now write:
final worklist = new Queue();
var compiler = new Compiler(worklist);
and both worklist and compiler will be initialized on first access.
We've also lifted the restriction for instance fields so the following
code now runs just fine:
class Cache {
final Map table = new Map();
...
}
as long as the initialization expressions do not refer to [this]. Such
expressions are evaluated when the object is created (not lazily on
first access as we do for static and top-level variables), but it cuts
down on the need for lengthy initializer lists in your constructors.
Cheers,
Kasper
--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
Huzzah!! So happy about this! Great work Dart team.
--