More than once, I have found that I want a variable visibility that is not possible in Java. I wanted some members to be visible within their class and within any subclasses, but not for the rest of the package or for the rest of the world. In other words, I wanted this:
Modifier Class Package Subclass World sub-class YNYN
However, the Java developers gave me this :
Modifier Class Package Subclass World public YYYY protected YYYN no modifier YYNN private YNNN
A typical case is when I want something like this when creating an abstract class. Sometimes I find that an abstract parent needs access to certain members, but specific children too. I can grant them this access by creating protected members, but this makes the rest of the package available when I don't want it.
To be completely understandable, I know that such a modifier is not possible in Java. My question is: why is such a modifier not included in Java? It seems to me that for me a more natural level of visibility than protected or the default. Is it the reason it is not so important to be included, or is it more related to possible side effects that I have not considered?
java visibility language-design
Michael McGowan Mar 14 2018-11-11T00: 00Z
source share