Since B
is not static, it needs some instance of A
to be able to exist, thus the error.
If B
is static, the error goes away.
Ah, forget about the nonsense. It is a bug, and it works on ideone in Java7 mode. However, prior to Java 7 it does not work - see this question, and you need to either
Change B to static
Add a constructor
C() {
A.this.super();
}
And then it will be working.
The reason why this happens before Java 7 might be the following which is from JLS:
Let C be the class being instantiated, let S be the direct superclass of C, and let i be the instance being created.
The implicit super
is called on the immediately enclosing instance of i with respect to S.
In the earlier JLS, the immediately enclosing instance is defined as
Let O be the innermost lexically enclosing class of which S is a member, and let n be an integer such that O is the nth lexically enclosing class of C. The immediately enclosing instance of i with respect to S is the nth lexically enclosing instance of this.
However, in Java 7:
Let O be the innermost lexically enclosing class of S, and let n be an integer such that O is the n'th lexically enclosing class of C.
The immediately enclosing instance of i with respect to S is the n'th lexically enclosing instance of this.
So in the past it was the innermost lexically enclosing class of which S is a member while now it is the innermost lexically enclosing class of S, so it changed from C
to A
, thus the code works in Java 7.