开发者

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

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<Stri开发者_运维百科ng> {
   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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜