The JLS says:
The constructor of a non-private inner member class implicitly declares, as the first formal parameter, a variable representing the immediately enclosing instance of the class.
Ok, if we write the following:
class A:
package org.gradle; public class A extends B.Inner{ public A(B b){ b.super(); //OK, invoke B.inner(B) } } class B:
package org.gradle; public class B{ public class Inner{ } } As said here, b.super() actually invoke B.Inner(B).
But if we write
class B:
package org.gradle; public class B { class Inner{ public Inner(B b){ System.out.println("Inner(B)"); } } } class A:
package org.gradle; public class A extends B.Inner{ public A(B b) { b.super(); //The constructor B.Inner() is undefined } } So, in the latter example b.super() tries to invoke B.Inner() instead. Why is that so difference?
b.super(b). The "invisible" first parameter isn't shown in the error message, because it's "invisible".b.super(5);in the first example, would you it say "B.Inner(B, int) is undefined" or "B.Inner(int) is undefined"?b.super()doesn't invokeB.Inner(B), but is in the first does?B.Inner(B).