public class A {
public class B {
}
};
需要实例B类时,按照正逻辑是,A.B ab = new A.B();
那么编译器就会出现一个错误–“is not an enclosing class”
再翻看相关的java代码,发现原来写法出错了!正确的做法是
A a = new A();
A.B ab = a.new B();
没有静态(static)的类中类不能使用外部类进行.操作,必须用实例来进行实例化类中类.
或
将内部类的方法都设置为static方法
标签:ash 一个 外部 ati das 实例化 需要 内部类 设置
public class A {
public class B {
}
};
需要实例B类时,按照正逻辑是,A.B ab = new A.B();
那么编译器就会出现一个错误–“is not an enclosing class”
再翻看相关的java代码,发现原来写法出错了!正确的做法是
A a = new A();
A.B ab = a.new B();
没有静态(static)的类中类不能使用外部类进行.操作,必须用实例来进行实例化类中类.
或
将内部类的方法都设置为static方法
[Java A] – is not an enclosing class
标签:ash 一个 外部 ati das 实例化 需要 内部类 设置
原文地址:https://www.cnblogs.com/yz123/p/11963312.html