Closures, too much or too little?
Roel Spilker
R.Spilker at topdesk.com
Tue Nov 24 01:56:30 PST 2009
One more thing. If there is a write to count after the assignment to count0, the compiler should give at least a warning. Otherwise the reader of this code could thing the closure would see the modification if the closure is used after the modification.
int count = 0;
count++;
Runnable r = #() {doSomethingWith(count);};
count++;
r.run();
would desugar to
int count = 0;
count++;
final int count0 = count; // generated
Runnable r = #() {doSomethingWith(count0);};
count++;
r.run();
In this scenario, I'd like to get an error or at least a warning that count is modified after the final variable has been assigned.
Roel
-----Oorspronkelijk bericht-----
Van: reinier at zwitserloot.com [mailto:coin-dev-bounces at openjdk.java.net] Namens Reinier Zwitserloot
Verzonden: dinsdag 24 november 2009 0:41
Aan: Mark Mahieu
CC: coin-dev
Onderwerp: Re: Closures, too much or too little?
Mark, spec-wise, "turning final" is effectively equivalent to the compiler desugaring your source code snippet to:
int count = 0;
final int count0;
count++;
count0 = count; //generated
Runnable r = #() {doSomethingWith(count0);};
More information about the coin-dev
mailing list