On 07/09/2011 12:21 PM, Rémi Forax wrote: > You should avoid to create constants more than once. > Also, bindTo() will create a method handle for-each call. > > You can transform your code like that: > > private static final MethodHandles.Lookup lookup = > MethodHandles.lookup(); > private static final MethodType mt = > MethodType.methodType(String.class, String.class); > > private static MethodHandle methodhandleLookup(Object receiver, String > methodName) throws Throwable { > return lookup.findVirtual(receiver.getClass(), methodName, mt); > } > > private static String methodhandleInvoke(Object receiver, MethodHandle > method) throws Throwable { > return (String) method.invoke(receiver, "methodhandle"); > } > > or like that: > > private static final MethodHandles.Lookup lookup = > MethodHandles.lookup(); > private static final MethodType mt = > MethodType.methodType(String.class, String.class); > private static final MethodType mt2 = > MethodType.methodType(String.class, Object.class, String.class); > > private static MethodHandle methodhandleLookup(Object receiver, String > methodName) throws Throwable { > MethodHandle mh = lookup.findVirtual(receiver.getClass(), > methodName, mt); > return mh.asType(mt2); > } > > private static String methodhandleInvoke(Object receiver, MethodHandle > method) throws Throwable { > return (String) method.bindTo(receiver).invokeExact(receiver, > "methodhandle"); > }
oups, typo: private static String methodhandleInvoke(Object receiver, MethodHandle method) throws Throwable { return (String) method.invokeExact(receiver, "methodhandle"); } > > Rémi Rémi _______________________________________________ mlvm-dev mailing list mlvm-dev@openjdk.java.net http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev