Community
Participate
Working Groups
// Code below compiles with javac 1.3, 1.4, and 1.5. Doesn't not // compile with Eclipse. Eclipse says // No enclosing instance of the type C1 is accessible in scope package p1; public class C1 { class Foo extends java.util.HashMap { Foo() { super( new java.util.HashMap() { public String toString() { return C1.this.toString(); } }); } } public String toString() { return "C1"; } }
Note that jikes is also reporting a problem. Found 1 semantic error compiling "C:/tests_sources/C1.java": 12. return C1.this.toString(); ^-----^ *** Semantic Error: An instance of "C1.this" exists, but is not accessible at this location because an intermediate anonymous type occurs in an explicit constructor call.
After reviewing JLS it seems Eclipse compiler is behaving correctly. See section 8.8.5.1 Explicit Constructor Invocations : http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#229267
Set bug to "invalid" as compiler behaves accordingly to the spec