Posts

Showing posts with the label inner-classes

Why is the data array in java.util.ArrayList package-private?

20 In the java.util.ArrayList class, the object array for the list's elements is defined as package-private: transient Object[] elementData; // non-private to simplify nested class access The comment states that the reason why this field is not private is easier access in nested classes. However, nested classes can access private data of the enclosing class just fine. So why is elementData not private? Is there something happening in the background (e.g., at compilation time)? java arraylist visibility inner-classes Share ...

Can't use public nested class as private method parameter

13 3 In the following code: class Outer { private: void f_private(Outer::Inner in); // Wrong public: class Inner {}; void f_public(Outer::Inner in); // OK }; f_private() cannot use nested class Outer::Inner as parameter type. But it's ok to do so in f_public() . Can someone explain to me in what rule this is based on, and what's the benefit it? c++ inner-classes access-modifiers public-members Share Improve this question Follow ...