程序如下:
import java.lang.*;
class ReflectTest
{
public static void main(String[] args)
{
String mainName=args[0];
Method method =Class.forName(mainName).getMethod("main",String[].class);
method.invoke(null,new Object[]{new String[]{"a","b","c"}});
}
}
class mainTest
{
public static void main(String[] args)
{
for(String arg:args)
{
System.out.println(arg);
}
}
}
程序中红色部分为什么要把new String["a","b","c"]放入new Object[]{}中,getMethod的类型不就是String[]吗?
|
|