开发者

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

开发者 https://www.devze.com 2023-04-12 06:34 出处:网络
I was trying to use an inner class of the super type, which was using generics. And got that strange error above.

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

精彩评论

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

关注公众号