What is the meaning of this?

Zdenek Tronicek tronicek at fit.cvut.cz
Thu Jan 28 22:56:23 PST 2010


Joshua Bloch napsal(a):
> More importantly, evaluating this in the enclosing context is
> perverse in Java. In every context where this is legal today, it refers to
> the innermost instance. It would be inconsistent to do otherwise for
> lambdas, and we would need a very good reason to knowingly create this
> inconsistency. I haven't heard any such reason. There is, however, a real
> disadvantage to making this refer to the enclosing instance: people will
> streamline existing code that uses anonymous classes, and could easily end
> up with code that doesn't compile or (worse) compiles but misbehaves
> because
> the meaning of this would be different in the new (lambda) and old
> (anonymous class) code.

There is a substantial difference between your view and view of
"transparency guys". You view closures as a concise notation of anonymous
classes and then you, naturally, expect that 'this' refers to the instance
of such class. "Transparency guys" view closures as blocks of code or
functions. Then, 'this' should refer to the enclosing instance.
So, the discussion is not about 'this', but about what the closures will be.

Z.
-- 
Zdenek Tronicek
FIT CTU in Prague



More information about the lambda-dev mailing list