The problem can be easily reproduced using this:
        MethodType type = MethodType.methodType(Constructor.class, 
Class[].class);
        MethodHandle mh = MethodHandles.lookup().findVirtual(Class.class, 
"getDeclaredConstructor", type);
        MethodType target = MethodType.methodType(Object.class, Object.class, 
Object.class);
        mh = mh.asType(target);
        mh.invokeWithArguments(Class.class,new Class[0]);

can someone tell me the mistake?

bye Jochen

Am 07.02.2012 17:04, schrieb Jochen Theodorou:
Hi all,

maybe someone can explain to me why method handles behave this way in my
case.

Bascially I have a handle for Class#getDeclaredConstructor(Class...) I
created via unreflect.

http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getDeclaredConstructor%28java.lang.Class...%29

this handle is then created as a AdapterMethodHandle$AsVargsCollector.
My targetType is Object(Object,Object) and the arguments to the call are
the Class, and an empty Class[]. So the next steps are asType with the
target type, adding a guard with catch, then my guards for the arguments
and last I do an invokeWithArguments.

What I get now is a ClassCastException with the message required class
java.lang.Class but encountered class [Ljava.lang.Class;

The guards are unrelated to the problem, since it happens without them
as well.

Now can anyone explain me why I get that exception? It doesn't really
make sense to me atm.

bye Jochen



--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

--
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com.
To unsubscribe from this group, send email to 
jvm-languages+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to