Project Lambda: Java Language Specification draft
Peter Levart
peter.levart at marand.si
Wed Jan 27 23:05:44 PST 2010
On Wednesday 27 January 2010 22:02:22 Neal Gafter wrote:
> 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.
>
And, equaly important, each construction creates new distinct state that further code refers to.
Regards, Peter
More information about the lambda-dev
mailing list