Project Lambda: Java Language Specification draft

Neal Gafter neal at gafter.com
Wed Jan 27 13:02:22 PST 2010


On Wed, Jan 27, 2010 at 12:47 PM, Zdenek Tronicek <tronicek at fit.cvut.cz> wrote:
> Of course, this is a perfect motivation. But, for me, it is so natural as
> if the compiler extract assignment to x out of the loop:
>
> int x;
> for (int i = 0; i < 10; i++) {
>  x = 42;
>  System.out.println(i);
> }
>
> The desugaring I mentioned should viewed as description of semantics. Not
> prescription to the compiler.

Because the identity of the resulting objects is observable, such an
optimization is not correct unless the identity is not specified.

For SAM classes it is even worse, because the construction time is
observable as an invocation of the constructor.


More information about the lambda-dev mailing list