Community
Participate
Working Groups
I20031008 Don't know if this is a bug or if I don't understand the meaning of the compile error. Compile the following class public class A { public void bar() { class C extends A { public void foo() { } } A a= new A() { public void foo() { } }; class D extends C { }; } }
---------- 1. ERROR in d:\eclipse\workspaces\dev3.0\plugins\Crap\src\A.java (at line 13) class D extends C { ^ No enclosing instance of type A is available due to some intermediate constructor invocation ---------- The error is valid though a little cryptic. Jikes would say: The innermost enclosing instance of type "A" is "this", which is not yet initialized here. javac 1.4.2 incorrectly accepts this code.
Problem is that constructor for D is trying to invoke super constructor from C, which requires an enclosing instance of type A. However, since D extends C extends A, it appears that 'this' (D) is the best candidate for such an enclosing instance. However, it is forbidden, since you are still in a constructor invocation (cannot use 'this'). Correct code should be: class D extends C { D() { A.this.super(); } also see bug 42588