I was wondering why Java has been designed without the friend
directive that is available in C++ to allow finer control over which methods and instance variables
In addition to the aforementioned package visibility, Java also offers inner and anonymous classes which are not only friends by default, but also automatically have a reference to the containing class. Since creating such helper classes is probably the only reasonable way to use friend
in C++, Java doesn't need it since it has another mechanism for that. Iterators are a very good example of this.