dyn:callMethod and varargs

Peter Zhelezniakov Peter.Zhelezniakov at oracle.com
Wed Mar 13 10:39:39 PDT 2013


Hello,

I'm looking for a way to pass variable-length list of arguments into a
Dynalink method handle. E.g. to implement a method like
    call(String methodName, Object obj, Object... args)

I'm trying
    Class[] argTypes = new Class[args.length + 1];
    Arrays.fill(argTypes, Object.class);
    MethodHandle function = Bootstrap.createDynamicInvoker(
            "dyn:callMethod:" + methodName,
            Object.class, argTypes);
    Object o = function.invokeExact(obj, args);

and getting an exception:

java.lang.invoke.WrongMethodTypeException: expected
(Object,Object,Object)Object but found (Object,Object[])Object

What else might I try?
Thanks!
-- 
Peter


More information about the nashorn-dev mailing list