problem with vargs method
jlaskey at mac.com
Tue Feb 7 08:31:32 PST 2012
As soon as you mh = mh.asType(target); it is no longer vararg, so it is treating new Class 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.
On 2012-02-07, at 12:14 PM, Jochen Theodorou wrote:
> 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);
> 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
>> Bascially I have a handle for Class#getDeclaredConstructor(Class...) I
>> created via unreflect.
>> 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
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
More information about the mlvm-dev