First draft of translation document

Rémi Forax forax at univ-mlv.fr
Tue May 18 01:11:57 PDT 2010


Le 18/05/2010 09:01, Gernot Neppert a écrit :
> Interesting to see the various possibilities of converting lambda
> expressions into callable Java objects!
>
> I wonder why the approach from paragraph 6.2 (Translation as inner
> class) is not also viable for paragrah 5 (stateless functions).
> Paragrah 5 relies on the assumption:
>
> "Additionally, we assume that the MethodHandle class will be extended
> to provide a method asSam(Class sam) which will provide an optimized
> form of injecting a SAM interface into a method handle."
>
> At the end of the day, doesn't that mean that an anonymous proxy class
> will be created anyway?
>    

No, not necessarily. That's why asSam() is cool.

The idea behind is to optimize the class that have only
one abstract method to store that method
in a special place and to have a specific path
in the VM to deal with these new kind of objects.

In that case method handles and SAM objects
can share the same representation in the VM
(or a similar one) thus the VM will be able
to create a new inner class from a method handle
without creating a new class.

> In what respect will your approach be superiour to simply generating
> code for a static inner class, such as:
>
> private static Block<T>  $sam$1= new Block<T>() {
>     public void invoke(String s){
>         System.out.println(s);
>     }
> };
>
>    

Rémi


More information about the lambda-dev mailing list