Your code compiles in Java 7.
The following compiler compiles for Java 6.
public class C extends B { public C() { A.this.super(); } }
@saugok a link to a previous question cites Joshua's explanation. Basically, he argued that since C is a subclass of A, C inherits the members of A as members of C. Therefore, B is also a member of C. (For example, let's say the class is the literal CBclass .) So he claims that C.this is an encompassing instance for B super() , so C(){super();} is actually C(){C.this.super();} . Because C.this cannot be evaluated before the super C.this , this is a mistake.
However, this is not like the language specification. See # 8.1.3. Since B not lexically enclosed in C , B not a direct inner class of C , there is no reason to say that an immediate instance of B must be an instance of C
We need to pass B() instance of A It is true that C.this is an instance of A (try this code: new C().new B().new C().new B(); ) so it can be a candidate. There is another candidate, A.this . A.this is accessible and ready to use (it passed as a hidden parameter to C() ).
According to javap , javac 7 compiles the code in
class B private A this$0; B( A a ) this$0 = a; super(); // A() class C extends B private A this$0; C( A a ) this$0 = a; super( a ); // B(A)
irreputable
source share