Am 07.02.2012 17:29, schrieb Jim Laskey:
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]);
As soon as you mh = mh.asType(target); it is no longer vararg, so it
is treating new Class[0] as the second argument cast to Object. If
you are trying to type as (Object , Object[]). I think you are going
to run into difficulties validating (Class[]) Object[]. You may have
to add a wrapper to get what you want, but you could also try using
asCollector.
or in other words: I should not use invokeWithArguments for this.
If I wanted to use the same target type... since that is what my call
site gives me... and I wanted to use invokeExact instead, how would I
have to change the program?
bye blackdrag
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en.