class Reflect_GetClassDemo
{
public static void main(String[] args) throws ClassNotFoundException,InstantiationException, IllegalAccessException
{
getClass_3();
}
public static void getClass_3() throws ClassNotFoundException,InstantiationException, IllegalAccessException
{
String className="Person";
Class clazz=Class.forName(className);
System.out.println(clazz);
//通过newInstance()就可以创建字节码对象所表示的类实例。
Object obj=clazz.newInstance();
System.out.println(obj);
}
}
大家好,谁能帮我看下是什么问题呀,编译可以通过,运行的时候不行。不知道问题出在了哪里
ClassNotFoundException,InstantiationException, IllegalAccessException
Exception in thread "main" java.lang.InstantiationException: Person
at java.lang.Class.newInstance(Class.java:359)
at Reflect_GetClassDemo.getClass_3(Reflect_GetClassDemo.java:49)
at Reflect_GetClassDemo.main(Reflect_GetClassDemo.java:20)
|