java - Inner class constructor invocation -
java - Inner class constructor invocation -
the jls says:
the constructor of non-private inner fellow member class implicitly declares, as first formal parameter, variable representing enclosing instance of class.
ok, if write following:
class a:
package org.gradle; public class 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() invoke b.inner(b).
but if 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 extends b.inner{ public a(b b) { b.super(); //the constructor b.inner() undefined } } so, in latter illustration b.super() tries invoke b.inner() instead. why difference?
it seek invoke b.inner(b) in sec example.
it can't find because there's b.inner(b, b). if constructor b.inner() gets changed inner(b)... , if constructor b.inner(b) gets changed b.inner(b, b).
note hidden parameter implementation detail, , unless you're studying how java compiler works, don't need know exists.
java
Comments
Post a Comment