How to make an outer class inherited from an inner class?

前端 未结 7 1161
执笔经年
执笔经年 2020-12-19 04:08

How can I make something like this work:

class Outer {
  int some_member;

  abstract class InnerBase {
    abstract void method();
  }
}

class OuterExtends         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-19 04:43

    Well your problem is that every instance of InnerBase (I know it's abstract) has to have a reference to an Outer object. That is part of the semantics of nested classes. Instantiating OuterExtendsInner would need such a reference. You can avoid that making InnerBase a static nested class.

提交回复
热议问题