本帖最后由 王金科 于 2012-8-27 11:34 编辑
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- public class Test {
- /**
- * @param args
- * @throws ClassNotFoundException
- * @throws SecurityException
- * @throws NoSuchMethodException
- * @throws InvocationTargetException
- * @throws IllegalArgumentException
- * @throws IllegalAccessException
- */
- public static void main(String[] args) throws NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // TODO Auto-generated method stub
- //调用一个类中的main方法
- //TestArguments.main(new String[]{"111","222","333"});
- String startingName = args[0];
- Method mainMethod = Class.forName(startingName).getMethod("main", String[].class);
- //mainMethod.invoke(null, new Object[]{new String[]{"111","222","333"}});
- mainMethod.invoke(null, (Object)(new String[]{"111","222","333"}));
- }
- }
- class TestArguments{
- public static void main(String[] args){
- for(String arg : args){
- System.out.println(arg);
- }
- }
- }
复制代码 以上是代码,运行eclipse要这样设置
程序是怎么解析这个参数的?
|