JSR 292 goodness: Lambda to SAM type conversion using invokedynamic

We made some interresting progress toward JSR 292 completion. As John already blogged[2], the latest build of jdk7 (b123) comes with a nearly up to date version of JSR 292 API. This build introduces a new mechanism that allow to send constant arguments to the bootstrap method of an invokedynamic. This blog entry is about how to use this feature to implement lambda to SAM type conversion.

Let suppose I want to translate this following code to bytecode.

Comparator<Object, Object> c = #{ o1, o2 -> 1 };

Currently (*), the prototype compiler of the lambda project, first create a static method (lambda$1) corresponding to the lambda then create a MethodHandle on this method. This method handle is after translated into an instance of class implementing the interface using a java.lang.reflect.Proxy.
Here, the lambda is not bound to any local arguments so the instance of the class Comparator can be created once. Using a trick similar to the one use to implement the DCL Pattern[3], it can be implemented using invokedynamic.

With invokedynamic it's simpler. But because there is no Java syntax for invokedynamic, I can't explain the translation using real Java code but in pseudo Java code, it's something like that: