为什么我的结果总是抛异常呢,看张老师的视频,结果是111, 222,333
请大家帮忙看看,谢谢大家了
package reflect1;
import java.lang.reflect.Method;
public class ReflectTo { public static void main(String[] args)throws Exception { //TestArguments.main(new String[]{"111","222","333"}); String startingClassName = args[0]; Method mainMethod = Class.forName(startingClassName).getMethod("main", String.class); mainMethod.invoke(new TestArguments(),(Object)new String[]{"111","222","333"});}}class TestArguments{ public static void main(String[] agrs){ for(String agr : agrs){ System.out.println(agr); } }}控制台结果Exception in thread "main" java.lang.NoSuchMethodException: reflect1.TestArguments.main(java.lang.String) at java.lang.Class.getMethod(Class.java:1655) at reflect1.ReflectTo.main(ReflectTo.java:9)
|