The reason I need the inner class to be non static is because I need the the inner class to have access to to a generic of the class which it is inside.
Thanks in advance.
Just like static members, a static nested class does not have access to the instance variables and methods of the outer class. You can extend static inner class with another inner class.
Non-static nested classes are called inner classes. Nested classes that are declared static are called static nested classes. A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private.
A final class cannot extended to create a subclass. All methods in a final class are implicitly final . Class String is an example of a final class.
Inner classes which do not reference their owning classes should be "static" A non-static inner class has a reference to its outer class, and access to the outer class' fields and methods. That class reference makes the inner class larger and could cause the outer class instance to live in memory longer than necessary.
I speculate that you want to extends a non-static inner class from outside an enclosing instance, which is possible.
class Alpha
{
class Beta ( ) { }
}
class Gamma extends Alpha . Beta
{
// important to get the constructor right or else the whole thing fails
Gamma ( Alpha alpha )
{
alpha . super ( ) ;
}
}
You can also extend the inner class inside the original enclosing class
class OuterParent
{
class InnerParent { }
class InnerChild1 extends OuterParent { }
}
or extend the original enclosing class and extend the inner class in the child class
class OuterChild extends OuterParent
{
class InnerChild2 extends OuterParent { }
}
Yes, it is possible. It will have access to the members of the enclosing class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With