hg: lambda/lambda/langtools: Handle non-static method references from static context. More specifically, if f is an instance method of Z whose signature is A, B->C, then #obj.f is of type A, B->C and #Z.f is of type Z, A, B->C.

Brian Goetz brian.goetz at oracle.com
Wed Aug 4 08:22:09 PDT 2010


> And the coolest thing is that #Employee.isPartTime is just a LDC.

Yep!  Tastes great AND less filling!

> Predicate<Employee>   p = #Employee.isPartTime;
>
> will be compiled to
>
> ldc #Employee.isPartTime
> ldc Predicate.class
> invokestatic MethodHandles.asSam
> (Ljava/lang/MethodHandle;Ljava/lang/Class;)LObject;
> checkcast LPredicate;
>
> knowing that asSam() should always return an instance of the same class
> for the same SAM.

Has the 292 EG made any progress in defining the semantics and nonfunctional 
behavior (i.e., performance) of asSam()?  I am curious to hear.  Will 
MethodHandles.asSam(methodHandle, clazz) allocate a fresh MH on each 
invocation, or will they be cached somehow so that the above is 
allocation-free (and subsequent invocation is indirection-free)?


More information about the lambda-dev mailing list