- public class Outer {
- public static void main(String[] args) throws InstantiationException, IllegalAccessException {
- new Outer().test();
- }
- private void test() throws InstantiationException, IllegalAccessException {
- System.out.println(new Inner()); //正常运行
- //System.out.println(Outer.Inner.class.newInstance());
- System.out.println(Inner.class.newInstance());
- }
- public class Inner{
- public String toString(){
- return "Inner case";
- }
- }
- }
复制代码 利用反射调用Inner构造器创建对象,运行异常:Outer$Inner,但前面加了外部类限定Outer.Inner.class.newInstance();依然是运行异常,这里应该怎样才能访问? |