Re: problem with vargs method

2012-02-09 Thread Volker Simonis
Jim's example works on 7u2 for me as well. The cast is not without effect at all. It is crucial to have it! That is because of the so called "Signature polymorphism" of the 'invokeExact()' and plain 'invoke()' methods (read the API documentation for more details: http://docs.oracle.com/javase/7/d

Re: problem with vargs method

2012-02-07 Thread Jim Laskey (Oracle)
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

Re: problem with vargs method

2012-02-07 Thread Jochen Theodorou
Am 07.02.2012 18:29, schrieb Jim Laskey: > Worked okay for me. So must be addressed in a later release. :-/ later than jdk7u2? oh boy. I would feel better if I could find a bug report that shows the problem and that is resolved. Then I would at least have something for the release notes. But I

Re: problem with vargs method

2012-02-07 Thread Jim Laskey
Worked okay for me. So must be addressed in a later release. :-/ On 2012-02-07, at 1:17 PM, Jochen Theodorou wrote: > > That will produce a > > java.lang.invoke.WrongMethodTypeException: > (Ljava/lang/Object;[Ljava/lang/Object;)V cannot be called without a receiver > argument as ([Ljava/l

Re: problem with vargs method

2012-02-07 Thread Jochen Theodorou
That will produce a java.lang.invoke.WrongMethodTypeException: (Ljava/lang/Object;[Ljava/lang/Object;)V cannot be called without a receiver argument as ([Ljava/lang/Object;)Ljava/lang/Object; imho casting to Object and Object[] in mh.invokeExact((Object)Class.class, (Object[])new Class[0]);

Re: problem with vargs method

2012-02-07 Thread Jim Laskey
Try MethodType type = MethodType.methodType(Constructor.class, Class[].class); MethodHandle mh = MethodHandles.lookup().findVirtual(Class.class, "getDeclaredConstructor", type); MethodType target = MethodType.methodType(void.class, Object.class, Object[].class); mh =

Re: problem with vargs method

2012-02-07 Thread Jochen Theodorou
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.me

Re: problem with vargs method

2012-02-07 Thread Jim Laskey
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

Re: problem with vargs method

2012-02-07 Thread Jim Laskey
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

Re: problem with vargs method

2012-02-07 Thread Jochen Theodorou
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.methodTyp

problem with vargs method

2012-02-07 Thread 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 thi