Community
Participate
Working Groups
This class of warning is never useful to me: class Base { private boolean _bool; } class Sub extends Base { private boolean _bool; // warning } I would like it to be suppressed, or to have an option to disable it. The warning in this case is especially irrelevant when Base is in a separate library. Broadly, my interest in the shadowing warning is limited to actual shadowing; shadowing which might occur if a private member were to become public in some future revision of a library is of no concern to me.
I'm sorry, I mistook my example. The indicated case is of no concern to me, but I'm not sure it would raise; the warning that's actually biting me is such: class Base { private boolean bar; } class Sub extends Base { public void foo( boolean bar // warning ) {} }
I don't get any shadowing warning with 3.2 RC3 with both of your examples. Please reopen if you have more details on how to reproduce.
Reopening. To reproduce: 1. Create a new project. 2. Open its Settings window. 3. Go to Settings > Java > Compiler > Errors/Warnings. 4. Enable project-specific settings. 5. Under "Name shadowing and conflicts", set "Field declaration hides another field or variable" to 'Error'. 6. Create a new class FalseShadowing in package test, and paste the following source code: package test; public class FalseShadowing { private static class A { private static A _instance = new A(); public A getA() { return _instance; } } private static class B extends A { private static B _instance = new B(); public A getB() { return _instance; } } } 7. Build, and observe the error: The field FalseShadowing.B._instance is hiding a field from type FalseShadowing.A This error is incorrect, since no actual shadowing occurs. To demonstrate, comment out this line: private static B _instance = new B(); And observe that A._instance is not accessible from B.
Reproduced with… Eclipse SDK Version: 3.2.0 Build id: I20060505-1306 Mac OS X 10.4.6; uname -a: Darwin localhost.localdomain 8.6.1 Darwin Kernel Version 8.6.1: Tue Mar 7 16:55:45 PST 2006; root:xnu-792.9.22.obj~1/RELEASE_I386 i386 i386
Changing OS from Mac OS to Mac OS X as per bug 185991
I agree, the warning shouldn't occur. The rule should be that it would only arise in a situation where you could reach the hidden declaration (and thus the code is somewhat suspicious). As you said, there is ambiguity here.