No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation

user911333 picture user911333 · Nov 18, 2011 · Viewed 18.8k times · Source

Consider the below code:

class abstract Normal1 extends Something 
{
}

class Outer 
{
  class abstract Inner extends Normal1
  {

  }
}

class General extends Outer.Inner  // Problem occurs at this 
{
}

The error I am getting is "No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation"

My question is can I extend the inner class like above ?

Answer

Jordão picture Jordão · Nov 18, 2011

Declare the inner class as static and you should be able to extend it:

class outer {
  static abstract class inner extends normal1 { }
}

If inner is not abstract, it's tied to outer, and can only exist when an instance of outer exists. Check to see if this is what you really want.