[239] in java-interest
Just to make "private" painfully clear.
daemon@ATHENA.MIT.EDU (Charles L. Perkins)
Thu Jun 8 14:34:10 1995
Date: Thu, 8 Jun 95 14:25:35 -0400
From: "Charles L. Perkins" <clp@home.HarvardSq.com>
To: java-interest@java.sun.com
Yes. Private is the default. Actually, you are not supposed to use the
"private" modifier because it is confusing. A private class does not
mean: it can only be accessed by this class (unlike private variables
an methods). Instead it means: it can only be accessed from this
package.
> Also, if private variables and methods are visible outside the package,
> they still pollute the namespace of any package that imports them!?! Is
> this really the case? I could see "protected" wanting to act this way
> perhaps, but not private. Arthur, can you clarify these points?
> | avh explains that private/public/protected for classes/methods works
> | like in C++: they affect accesability, not visibility.
>
> OK; not my prefered semantics, but there is an argument for it.
>
> | Then he says...
> |
> | private classes/methods/variables should not pollute the name space.
>
> I don't get this. It *is* polluting my name space. I cannot use the
> name of a method that is private because I might create an illegal ambiguity.
>
> Am I missing something?
The confusion is caused by the fact the current compiler does not
realize that some classes are private and should not pollute the
name space. This is due to a bug in the compiler. It will be fixed
in the next release. Sorry for the confusion.
[...later reply:]
If I understand the previous mail then, "private" in classes affect
visibility (outside the package), while "private" in a method affects
accessability only but not visibility (outside the class).
So to summarize, "private" does not mean ANYTHING LIKE the same thing
for classes and interfaces as it does for methods and variables. (IMHO
it should just be *deleted* in that case! It serves only to confuse.)
It also means there is no way for a class to be used by another class
(only) without putting them both in a package created for that purpose.
Also: there's a bug with the class implementation of private (and the
default, since they're the same, right?) that makes everything visible.
Finally, about private methods and variables:
(1) I don't see why separating accessibility from visibility is such
a great idea (the only thing I could think of was if the accessibility
of a class' contents changes over time, this allows other classes that
depend on that content to not become, e.g., (compile-time) ambiguous.
Is there some other philosophical language reason?
(2) Arthur, you still didn't answer the pollution question fully. Why
should a fully PRIVATE variable or method (one that I can't use) cause
me to have to fully disambiguate my own method or variable of the same
name? I.e., (a) do I have to do this? (b) why? The above reason only?
Sorry to be a stickler about this, but I want to be sure I not only
understand the current behaviour of java (bugs and all) but what was
intended and why.
Thanks,
Charles
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com