What is the meaning of this?
Joshua Bloch
jjb at google.com
Tue Feb 2 10:17:03 PST 2010
Zdenek,
Hi. I'm back from vacation and catching up. While I believe there's
something to what you say, it's not so much that I view closures as "a
concise notation of anonymous classes"; I view them as a concise notation
for function objects. But they *are* objects, with identities and classes.
There *are *primitives, which lack an identity distinct from their value,
but the objects returned by evaluating lambda expressions are not primitive
values. I believe the notion of "transparency" that some are arguing for
conflicts with basic design principles of Java in a way that's likely to
cause trouble. It glosses over the identity of a lambda without eliminating
it entirely.
Josh
On Thu, Jan 28, 2010 at 10:56 PM, Zdenek Tronicek <tronicek at fit.cvut.cz>wrote:
> 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