Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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<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?

like image 217
Christian Avatar asked Oct 09 '11 13:10

Christian


1 Answers

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.

like image 61
Christian Avatar answered Nov 13 '22 22:11

Christian