- class Test{
- public static void main(String[] args) throws Exception {
- Demo.main(new String[]{"obj1","obj2"});
- Method method = Demo.class.getMethod("main", String[].class);
- method.invoke(null, (Object)(new String[]{"obj1","obj2"}));
- }
- }
复制代码 2个问题,一个是 Class.forName()方法必须是完整路径
第二个是把new String[]{"obj1","obj2"}转成object,不让主函数剥皮 |