代码示例:
public class Foo
{
public class Bar
{
public void printMesg(String body)
{
System.out.println(body);
}
}
public static void main(String[] args)
{
// Creating new instance of 'Bar' using Class.forname - how?
}
}
是否可以通过类名创建一个新的Bar实例?我尝试使用:
Class c = Class.forName("Foo$Bar")
它找到了这个类,但是当我使用c.newInstance()时它抛出InstantiationException异常。
InstantiationException
的详细信息是什么? - Andrew Hare