1 package test4; 2 3 import java.lang.invoke.*; 4 5 public class InvokeDyn { test9(int i, String s)6 public static int test9(int i, String s) { return 9; } test8(int i, String s)7 public int test8(int i, String s) { return 8; } 8 boot(MethodHandles.Lookup caller, String name, MethodType type)9 public static CallSite boot(MethodHandles.Lookup caller, String name, MethodType type) 10 throws NoSuchMethodException, IllegalAccessException 11 { 12 MethodHandles.Lookup lookup = MethodHandles.lookup(); 13 Class thisClass = lookup.lookupClass(); 14 MethodHandle method = lookup.findStatic(thisClass, "test9", MethodType.methodType(int.class, int.class, String.class)); 15 return new ConstantCallSite(method); 16 } 17 boot2(MethodHandles.Lookup caller, String name, MethodType type)18 public CallSite boot2(MethodHandles.Lookup caller, String name, MethodType type) 19 throws NoSuchMethodException, IllegalAccessException 20 { 21 MethodHandles.Lookup lookup = MethodHandles.lookup(); 22 Class thisClass = lookup.lookupClass(); 23 MethodHandle method = lookup.findVirtual(thisClass, "test8", MethodType.methodType(int.class, int.class, String.class)); 24 return new ConstantCallSite(method.asType(MethodType.methodType(int.class, Object.class, int.class, String.class))); 25 } 26 } 27