POC javac can compile invokedynamic

Charles Oliver Nutter charles.nutter at sun.com
Fri Sep 12 21:49:28 PDT 2008


John Rose wrote:
> I just put out a patch (mlvm/langtools/meth.patch) which allows javac  
> to compile MH and invokedynamic calls.
> 
> This should make it easier to experiment with the modified JVM,  
> without resorting to direct bytecode editing or assembling.
> 
> Caveat:  I don't know whether this is the right way for javac to go  
> in the long run; please treat the present design as a tentative  
> experiment.

If there were any long-term prospects for this to stick around, here's a 
cute hack to make it easier:

// DynamicUtil.java
public class DynamicUtil {
   public static Dynamic Dynamic(Object object) {
     return (Dynamic)object;
   }
}

// MyCode.java
import static DynamicUtil.Dynamic
public class MyCode {
   public void doSomething() {
     String a = "foo";
     Dynamic(a).someOtherMethod();
   }
}

Pretty cute that javac allows things like that.

- Charlie



More information about the mlvm-dev mailing list