【发布时间】:2017-10-31 18:31:51
【问题描述】:
我想用列表参数调用函数,代码如下:
class A {
def cat(s1: String, s2: String) = s1 + " " + s2
}
val a = new A
val mylist = Array("hello","guys")
val argtypes = mylist.map(_.getClass)
val method = a.getClass.getMethod("cat",argtypes: _*)
method.invoke(a,argtypes: _*)
但我收到错误:
java.lang.IllegalArgumentException:参数类型不匹配 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:606)
我该怎么做?
【问题讨论】:
标签: scala reflection