Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 537
user911333 Avatar asked Nov 18 '11 04:11

user911333


4 Answers

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.

like image 199
Jordão Avatar answered Nov 11 '22 04:11

Jordão


Nested class are like(in sense ) Property of a class.

  1. As in case of instance variable it only when available when its object is created as same as inner class also available when outer's object will created.

So if you want to extend this then make your inner class as static inner class
As jordao suggest above

like image 43
Sumit Singh Avatar answered Nov 11 '22 06:11

Sumit Singh


Try this, (Read nested class inheritance rules).

abstract class normal1 extends something { }

class outer
{
  abstract class  inner extends normal1{}
}

class Outer1 extends outer
{
  class General extends inner {}
}
like image 2
KV Prajapati Avatar answered Nov 11 '22 06:11

KV Prajapati


In your class General modify its constructor a to call super inner class constructor. here is the code..

public General(){
    new outer().super();
}
like image 2
Siddappa Walake Avatar answered Nov 11 '22 06:11

Siddappa Walake