2
我想调用与列表参数函数参数类型不匹配,这是代码:斯卡拉:当调用参数列表
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(本机方法)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.in参数类型不匹配voke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:606)
我该怎么办呢?
谢谢!它运作良好。 – meng