【发布时间】:2013-12-01 20:10:59
【问题描述】:
我正在学习嵌套类和内部类,这让我思考是否可以将内部类扩展为嵌套类。例如。
public class Outer{
public class Inner{
// notice the lack of static keyword
}
}
public class ExtendedOuter extends Outer{
public static class ExtendedInner extends Inner{
// notice the static keyword
}
}
我确实尝试编译上面的代码,但我不能,但我收到的编译时错误让我相信可能有一个解决方法。但是,我可以将嵌套类扩展为内部类。
这是我收到的编译时错误。
范围内没有外部类型的封闭实例
【问题讨论】:
-
static类不能扩展非static内部类。 -
Inner应该是静态的,否则它必须绑定到Outer的实例,就像错误消息告诉你的那样。
标签: java compiler-errors compiler-warnings inner-classes