public class ReflectTest {
public static void main(String[] args) throws Exception{
Person s=(Person) constructor2.newInstance();
System.out.print(s.age);
}
}
class Person{
int age=10;
String name;
void study(){
System.out.println("好好学习");
}
}
1.Exception in thread "main" java.lang.NoSuchMethodException: com.itcast.day1.Person.<init>(com.itcast.day1.Person)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at com.itcast.day1.ReflectTest.main(ReflectTest.java:15)
运行报错 不知如何是好 刚接触反射 不是太会玩 作者: 杜正华 时间: 2012-10-13 18:05
package com.itcast.practise;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public class Demo1 {
public static void main(String[] args)throws Exception{