我很想知道为什么下面的实例将不能编译:Java对象实例 - 什么不对的:
Superclass.Subclass myObject = new Superclass.Subclass();
错误消息如下:
No enclosing instance of type Superclass is accessible. Must qualify the allocation with an enclosing instance of type Superclass (e.g. x.new A() where x is an instance of Superclass).
是什么意思通过外围实例?为什么是这个必要吗?
看来这消息说明该语法必须是:
Superclass mySuperObj = new Superclass();
Superclass.Subclass mySubObj = mySuperObj.new Subclass();
,但它无法解释什么是错我的方法为什么必须使用这种替代语法。
哪里是代码,声明超类和子类?你应该发布[mcve] - 在你的情况下,你应该关注** Complete **的C。 –