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).
_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to