What is the meaning of this?

Neal Gafter neal at gafter.com
Tue Feb 2 10:40:39 PST 2010


I think Zdenek had it exactly right.

A lambda expression is not an object creation expression.  The function is
not declared within the scope of some object type.  A lambda is written as
an independent block of code, and should be scoped accordingly.  Trying to
make a lambda act the same as an anonymous class creation expression smacks
of cargo-cult language design.

Cheers,
Neal

On Tue, Feb 2, 2010 at 10:17 AM, Joshua Bloch <jjb at google.com> wrote:

> 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