自定义一个类叫Student,通过反射取构造函数的时候发生异常,这是为什么呢
class ReflectTest
{
public static void main(String[] args) throws Exception
{
Constructor constructor=Class.forName("Student").getConstructor(String.class,int.class);
Student s=(Student)constructor.newInstance(new String("张三"),23);
}
}
class Student
{
private String name;
private int age;
Student(String name,int age)
{
this.name=name;
this.age=age;
}
} |
|