我在类中有一个方法如下
class Sample{
public void doSomething(String ... values) {
//do something
}
public void doSomething(Integer value) {
}
}
//other methods
.
.
.
Run Code Online (Sandbox Code Playgroud)
现在我得到IllegalArgumentException:下面的参数数量错误
Sample object = new Sample();
Method m = object.getClass().getMethod( "doSomething", String[].class );
String[] arr = {"v1","v2"};
m.invoke( object, arr ) // exception here
Run Code Online (Sandbox Code Playgroud) 如果我有一个方法,它采取一个int[]参数,我希望调用method.invoke此,那么我需要做以下事情
Object[] anArray = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
method.invoke(obj, anArray);
Run Code Online (Sandbox Code Playgroud)
它是否像我似乎得到错误一样简单?
问候