Updated State of the Lambda
Peter Levart
peter.levart at marand.si
Mon Oct 18 07:05:50 PDT 2010
On 10/18/10, Rémi Forax wrote:
> > Why could the compiler not recognise the use of (lambda) this and
> > provide it as an argument as you suggest?
>
> Because it's not the same object. If you mutate a method handle, you
> create a new one
> due to its immutable nature.
>
Ah, now I understand your concern. You would like lambda expressions to be convertible to method handles (java.dyn.MethodHandle) as well as to SAM types.
> MethodHandle mh = #{ MethodHandle anotherMH -> mh == anotherMH };
> mh.invokeGeneric(mh) // false
>
> because, it's translated to:
>
> static boolean lambda$1(MethodHandle mh, MethodHandle anotherMH) {
> return mh == anotherMH;
> }
>
> MethodHandle mh = #lambda$1;
> mh = mh.bindTo(mh);
>
> mh.invokeGeneric(mh); // return mh == #lambda$1 => false
Why couldn't compiler translate it to:
static boolean lambda$1(MethodHandle anotherMH) {
return #lambda$1 == anotherMH;
}
MethodHandle mh = #lambda$1;
mh.invokeGeneric(mh); // return #lambda$1 == #lambda$1 => true?
Peter
More information about the lambda-dev
mailing list