我有这样的代码:
class TopLevelClass {
private String outstr= "outer";
public String str = "str toplevel";
class Inner01 extends TopLevelClass {
private String strInn01 = "strInn01";
private String str = "strInner01";
String getOutStr() {
return outstr;
}
void printStr() {
System.out.println("Inner01>" + str);
System.out.println("Inner01>" + Inner01.super.str);
}
class Inner02 extends Inner01 {
public Inner02() {
this(new TopLevelClass().new Inner01()); // here is compile error
}
public Inner02(TopLevelClass.Inner01 o) {
o.super();
}
}
}
}
编译错误"无法引用' Inner01'在超类型构造函数被调用之前" 。
你可以解释一下原因吗?使用这种架构在Inner02
类中创建构造函数的正确方法是什么?