Kasper Lund
unread,Sep 14, 2012, 9:34:31 AM9/14/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to General Dart Discussion
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