Invokedynamic and Multiple Dispatch
Larry Chester
larry.chester at googlemail.com
Sat Mar 6 17:21:35 PST 2010
Thanks for your reply!
My aim is to dispatch based on the dynamic type of the Object as described in:
http://en.wikipedia.org/wiki/Multiple_dispatch
Currently my implementation revolves around building a HashMap that
maps a dynamic type to a MethodHandle and invoking that:
HashMap<Class, MethodHandle> lookup = new HashMap();
MethodType type = MethodType.methodType(void.class, String.class);
MethodHandle func = MethodHandles.lookup().findStatic(Main.class, "foo", type);
lookup.put(String.class, func);
Then to invoke on an Object x:
lookup.get(x.getClass()).invokeGeneric(x);
This is quite slow though (although I believe the bottleneck is in the
invokeGeneric call).
More information about the mlvm-dev
mailing list