I'm trying to invoke a method via reflection by passing the method's invocation arguments in an array. Params is a List [Any] and carries the values to be passed to the reflected method.
// make absolutely sure it's of the correct type
val args : Array [Object] = params.map (_.asInstanceOf [java.lang.Object]).toArray
System.err.println ("target method: " + method.getName + " :: " + method.getParameterTypes.toList)
System.err.println ("parameters : " + args.getClass.getCanonicalName + "\n " +
(args map (p => (p.getClass.getCanonicalName, p))).toList)
method.invoke (host, args)
I get the following output, which all looks good. The signature of the method being invoked matches the parameter list perfectly.
target method: echo :: List(class java.lang.String)
parameters : java.lang.Object[]
List((java.lang.String,looks good))
Sadly, the invoke throws java.lang.IllegalArgumentException: argument type mismatch
According to the Java docs a varargs argument (as the params to Method.invoke are) can be supplied with an Object[]. I'm stumped!