[英]Is it possible to extend a non-static inner class in Java?
我需要内部类是非静态的原因是因为我需要内部类来访问它所在的类的泛型。
提前致谢。
我推测你想从一个封闭的实例外部扩展一个非静态的内部类,这是可能的。
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 ( ) ;
}
}
您还可以在原始封闭类中扩展内部类
class OuterParent
{
class InnerParent { }
class InnerChild1 extends OuterParent { }
}
或者扩展原始的封闭类并扩展子类中的内部类
class OuterChild extends OuterParent
{
class InnerChild2 extends OuterParent { }
}
对的,这是可能的。 它将有权访问封闭类的成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.