Community
Participate
Working Groups
I'm working on some code similar to below and I'm experiencing differences between the Sun java compiler and the Eclipse incremental compiler in how they see protected attributes of a class. In Eclipse, I get the error "Type myPrivateClass.Goober is not visible." on all accesses to x, y, and z. But when I compile the code using 1.4.2_01 of the Sun SDK I only receive 2 errors one on x and the other on z. -8< file: myPrivateClass.java ---------------------------- package myPackage; public final class myPrivateClass { private class Goober { private int x; protected int y; public int z; } Goober goober = new Goober(); } -8< file: myTestClass.java ------------------------------ package myPackage; public class myTestClass { public void lmnop() { myPrivateClass x = new myPrivateClass(); x.goober.x = 0; // private not accessable via javac x.goober.y = 1; // protected accessable via javac x.goober.z = 2; // public not accessable via javac } } -8< file: build.xml ------------------------------ <project name="stuff" default="default" basedir="."> <property name="build.dest" value="./bin" /> <target name="default"> <mkdir dir="${build.dest}"/> <javac srcdir="." destdir="${build.dest}" /> </target> </project>
In 3 cases, we complain that the declaring class of the field (Goober) is not visible. Since it is accessed 3 times in the same way, I don't see the problem to have them all issue the same error. I would say this is a bug in javac. The protected field shouldn't be more accessible than the public one.
I agree with you, one should not be more visible than another. The real problem is the difference in the compilers. I once worked on a product where we had to be bug-for-bug compatible with another product. The Eclipse compiler team just needs to decide what they want the experience of the end user to look like. This issue might prevent me from deploying Eclipse as a development environment (which I really want to do). Perhaps an option to the compiler that enables the "features" of the Sun compiler could be implemented?
We cannot and certainly do not want to be bug compatible with javac. Check out the bug database for javac and you'll get an idea of what I mean. Why should we emulate Sun behavior ? You should argue with them they should fix this bug.
Invalid