Primitives in Generics (+ the meaning of this)

Reinier Zwitserloot reinier at zwitserloot.com
Fri Jul 16 11:56:31 PDT 2010


In both cases, the way brian puts it, the first call will resolve to the
same method as this call:

foo(new Runnable() {public void run(){}});

and the second:

Callable<?> c = null;
foo(c);


After all, the 'this' refers to the closures themselves, and the type of the
closure is determined BEFORE the code in the closure is resolved. In both of
these cases the (so far hypothetical) SotL closure type resolver would
trivially resolve these by looking at the target types of these variable
declarations, which are Runnable and Callable<?> respectively.

In an alternate proposal where 'this' refers to outer, then both would
resolve to whatever this call to foo resolves to:

WhateverTypeTheseClosuresAreIn x = null;
foo(x);

i.e. 'foo(this)' in a closure would be no different from the same thing
outside of it.

Or so I understand SotL and the discussed alternative, at any rate.

 --Reinier Zwitserloot



On Fri, Jul 16, 2010 at 7:54 PM, Rémi Forax <forax at univ-mlv.fr> wrote:

> Le 16/07/2010 19:25, Neal Gafter a écrit :
> > On Fri, Jul 16, 2010 at 10:07 AM, Brian Goetz<brian.goetz at oracle.com
> >wrote:
> >
> >
> >> And, given that inner classes *already* suffer from the accidental
> >> shadowing
> >> problem, creating a mechanism that goes the other way (even if the other
> >> way
> >> is absolutely right!) is even more confusing for Java developers, who
> now
> >> have
> >> to keep track of two separate and inconsistent bits of puzzlerhood.
> >>
> >>
> > Brian-
> >
> > I don't believe it would be more confusing for Java developers (except
> those
> > completely unfamiliar with the new language feature).  But setting that
> > aside, this leads to the natural question: If we're wanting to recreate
> all
> > the problems of anonymous inner classes, what, if any, problems ARE
> > addressed by project lambda, and what is newly possible that was not
> > possible previously?
> >
> > -Neal
> >
>
> Good question. and I haven't no good answer.
>
> Runnable r = { -> foo(this); }
> Callable<?> c = { -> foo(this); }
>
> what is the signature of foo in those cases ?
>
> BTW, there is at least something that inner-class does and lambda doesn't.
> You can send argument to the constructor of an inner-class
> and you can't do that with lambda.
>
> Rémi
>
>


More information about the lambda-dev mailing list