I looked in the Java specification, and I didn't find anything explicitly stated about this. My guess is that because an inner class is only defined with respect to an instance of it's enclosing class, the enclosing class and other inner classes can have access to its private members.
I didn't find a bug report about it. Also I downloaded Mustang and it compiled fine, so my guess is that it must be a feature and not a bug, although I haven't found any confirmation about that.
The outer and inner classes can access each other's state, even if it is private. Stylistically, they are basically one implementation code base, so mixing access is ok, but we prefer receiver-relative coding for both the outer and inner classes where it makes sense.
[Keith]: I looked in the Java specification, and I didn't find anything explicitly stated about this.
It's part of the fundamental definition of what private means in the first place. From JLS3 6.6.8:
A private class member or constructor is accessible only within the body of the top level class (�7.6) that encloses the declaration of the member or constructor.
The phrase "within the body of the top level class" is key. The word private has always allowed access within the same top-level class. This isn't as widely known as it probably should be - I'm guessing that's because people often learn about access modifiers before they learn about nested classes, and so they learn a simplified version of private that doesn't mention nested classes. [ June 22, 2006: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
posted 13 years ago
Thanks Jim. I was looking in the wrong place. I went through the part that was specifically about inner classes.