Despite the fact that I have been developing Java for life for 11 years, I was terrified when I discovered this fact two (!) Years ago. I must have read this before, but somehow it never sank. I agree that at first it seems strange, but when you think about it a little longer, it makes sense.
What is OO? About sharing problems and hiding information, right? Therefore, in your design you should always (should) try to avoid "knowing" about things outside of your own care, because this is tantamount to assumptions; what you know "at design time may change later and invalidate the assumption that your class makes.
In this case, you allow Foo to access another private Foo panel that first feels βawareβ of something out of focus. But since we are talking about two instances of the same class (Foo), this is actually not beyond our concern! If, for example, we change the bar from int to double, we do it in one class, and any compilation errors will be displayed immediately.
Also imagine that this type of access was denied. So what if Foo called his own compareTo, passing 'this' as an argument? Then we would have to forbid Foo to access his own private bar? What about private static fields? That would be very strange, right?
A little long, perhaps, but I hope you can appreciate that after the first shock it really makes sense! (-:
source share