On 02/07/2012 07:38 PM, Jochen Theodorou wrote:
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 didn't find anything
that looks fitting. The only one that seems to be slightly fitting was
fixed a year ago and surely that fix is part of jdk7u2 already.
You said for
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]);
I probably have to wrap something... can you explain what you mean?
bye Jochen
Jochen,
I believe you have found a bug in Eclipse (I suppose you use Eclipse).
mh.invoke() is compiled as (Object)mh.invoke() by Eclipse instead of
(void)mh.invoke(),
hence that's why it works for Jim and not for you.
Now, how varargs works.
when you create a method handle with lookup.find* or lookup.unreflect()
on a method
which is a varargs (compîled with the ACC_VARARGS bit) then
the created method handle has its varargs collector bit set.
A way to test if the varargs collector bit is set or not is to call,
methodHandle.isVarargCollector().
A method handle with the a varargs collector bit set is able to group
arguments in an array
only if invoked with invoke() or invokeWithArguments() but not with
invokeExact which
never do any boxing or varargs magics.
Also, when asType() is called on a method handle, the varargs collector
bit set is lost,
so if you still want a varargs call you need to call
asVarargsCollector() to set the bit.
As a meta-note, invoking a method handle with invoke or invokeArguments and
the varargs collector bit set is slow. It's only intended to be use when
you want to call a lambda/closure that is defined as a varargs.
Otherwise you should use asCollector which is way faster (at least
currently with Hotspot).
cheers,
Rémi
--
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.