Because the inner class builder must be associated with a handle to the encapsulated class object, the situation becomes slightly more complex when inheriting from an inner class. The problem here is that the "secret" handle of the encapsulated class must be initialized, and there is no longer a default object in the derived class that can be connected. The solution to this problem is to use a special syntax that explicitly establishes this association:
: Inheritinner.java
//Inheriting an inner class
class Withinner {
class Inner {}
}
Heritinner
extends Withinner.inner {
//! Inheritinner () {}//Won ' t compile
inheritinner (Withinner wi) {
wi.super ();
}
public static void Main (string[] args) {
Withinner wi = new Withinner ();
Inheritinner II = new Inheritinner (WI);
}
///:~
As you can see, Inheritinner only extends the inner class and does not extend the external classes. But when you need to create a builder, the default object is meaningless, and we can't just pass a handle to the encapsulated object. In addition, the following syntax must be used in the builder:
Enclosingclasshandle.super ();
It provides the necessary handles so that the program compiles correctly.