运行环境:jdk1.7
原因:我无论怎么试,打印的语句最后总是有一句null。求解决,我看了半天我代吗没错。、
求解决:
要调用此类的Main方法:
class MainTest {
public static void main(String[] args) {
for (String arg:args){
System.out.println(arg);
}
}
}
测试类:
public class MothodMain {
public static void main(String[] args)throws Exception {
MainTest.main(new String[]{"111","222","333"});
//这里传入我要调用某类的main方法的类名
String startName=args[0];
Method method=Class.forName(startName).getMethod("main", String[].class);
String[] str={"haha","hoho","momo"};
System.out.println(method.invoke(null, new Object[]{str}));
}
}
|