[code=java]import java.lang.reflect.Method;
import org.junit.Test;
public class People {
public void printNum1 ( String[] nums){
for(String num : nums){
System.out.println(num);
}
}
public void printNum2 ( int[] nums){
for(int num : nums){
System.out.println(num);
}
}
@Test
public void test1() throws Exception{
Class clazz = People.class;
Method method = clazz.getMethod("printNum1", String[].class);
method.invoke(new People(), new String[]{"hello","word"});
}
@Test
public void test2() throws Exception{
Class clazz = People.class;
Method method = clazz.getMethod("printNum2", int[].class);
method.invoke(new People(), new int[]{1,2});
}
}[/code]questions:test1有问题,test2正常。这是为什么?
[ 本帖最后由 沈雷 于 2011-08-04 16:22 编辑 ] |
|