Am 07.02.2012 20:14, schrieb Rémi Forax:
[...]
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.
No actually your long explanation gave me the idea of what is wrong
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.
ok, explicitCastArguments will do probably needed casting and boxing for
me, and since Groovy does the vargs logic on its own, there seems to be
no reason to still use invokeWithArguments anymore. I only failed to
understand invokeExact till now.
What I stupidly failed to see is that invokeExact itself realizes a call
site and thus has a different target type.
so what I do now is
MethodHandle call = handle.asSpreader(Object[].class, args.length);
call = call.asType(MethodType.methodType(Object.class,Object[].class));
and then I can do my
call.invokeExact(args)
without problem it seems.
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 [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.