Community
Participate
Working Groups
In the following example (which compiles fine with both Sun 1.3.1_06 & Sun 1.4.1_01), Eclipse claims that the constructor A() is not visible in B: public class A { protected A _instance = new A(); protected A() {} } public class B extends A { public static void resetInstance() { _instance = new A(); }
Could you please specify which build you are using? Using 2.1 latest code, I got: ---------- 1. ERROR in D:\temp\B.java (at line 3) _instance = new A(); ^^^^^^^^^ Cannot make a static reference to the non-static field _instance ---------- 1 problem (1 error) I had to add a closing '}' in B. My test case is: 1) save this code in A.java: public class A { protected A _instance = new A(); protected A() {} } 2) save this code in B.java: public class B extends A { public static void resetInstance() { _instance = new A(); } } 3) Compile both using the batch compiler or a self-hosting workspace. If I remove the static modifier in B, then it compiles fine. Could you please provide the exact steps to reproduce? Thanks for the report.
I'm sorry for the bugs in the example and lost details -- I was doing it from memory. I've reverified, and here are the class definitions. The important part is that B is not in the same package as A. This was done with M4. The error I get is "The constructor A() is not visible." ------------ package main; public class A { protected static A _instance = new A(); protected A() {} } ------------ package main.test; import main.A; public class B extends A { public static void resetInstance() { _instance = new A(); } }
And, after thinking about it, I redid the test using SDK 1.4.1_01 and SDK 1.3.1_06 (I think that I forgot the packages when I tested the first time) and it fails there too. My apologies.
Ok to close?
Yes, my bad.
Close as INVALID.