No enclosing instance of type MySuperClass<B> is available due to some intermediate constructor

▼魔方 西西 提交于 2019-12-09 09:23:47

问题


I was trying to use an inner class of the super type, which was using generics. And got that strange error above.

class MySuperClass<B> {
   class InnerClass {
   }

   MySuperClass(InnerClass... c) {
   }
}

In the sub class I tried to instantiate it:

class MySubClass extends MySuperClass<String> {
   MySubClass() {
      super(new InnerClass(), new InnerClass());
   }
}

The compiler confused me with

No enclosing instance of type MySuperClass<B> is available due to some intermediate constructor

Why?


回答1:


Heh, and found the answer myself:

The InnerClass is not static thus an instance of MySuperClass must be passed for the this$ reference - but that's not available before the super() call... simply making InnerClass static solved my problem.



来源:https://stackoverflow.com/questions/7703812/no-enclosing-instance-of-type-mysuperclassb-is-available-due-to-some-intermedi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!