为什么我这个javaDemo里的Demo1是不能解决的?什么意思?
- import java.lang.reflect.*;
- import java.util.*;
- public class Javademo {
- public static void main(String[] args)throws Exception
- {
- //普通方式
- Dome1.main(new String[]{"123","456","789"});
- System.out.println("....................");
- //反射方式
- String className = args[0];
- Class clazz = Class.forName(className);
- Method methodMain = clazz.getMethod("main", String[].class);
- //转为Object,不拆包
- methodMain.invoke(null, (Object)new String[]{"123","456","789"});
- //将数组打包
- methodMain.invoke(null, new Object[]{new String[]{"123","456","789"}});
- }
-
- }
- class Demo1
- {
-
- public static void main(String[] args) // throws IOException
- {
- for(String arg:args)
- {
- System.out.println(arg);
- }
- }
- }
复制代码 |
|