package itcast.javabean;
public class Person {
private String name;
private int age;
public Person() {
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package itcast.javabean;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
public class BeanReflection {
public static void main(String[] args) throws Exception {
Constructor[] constructor=Class.forName("itcast.javabean.Person").getConstructors();
System.out.println(constructor.length);
for(Object obj:constructor){
System.out.println(obj);
}
Constructor constructor1=Class.forName("itcast.javabean.Person").getConstructor(Person.class);
System.out.println(constructor1);
}
}
我能获取到所有的构造函数,为什么我获取单个构造函数的时候就给我报java.lang.NoSuchMethodException!
求教啊? |