...
This compliant solution declares a public private array and provides public methods to get individual items and array size:
...
As before, this method provides direct access to the array objects themselves, but this is safe because String
is immutable. If the array contained mutable objects, the getItems()
method could should return an array of cloned objects instead.
...
Item 13, "Minimize the Accessibility of Classes and Members" | |
[Conventions 2009] | |
Chapter 6, "Interfaces and Inner Classes" | |
[JLS 2015] | |
Section 2.2, "Public Fields" | |
Class Properties for Security Review in an Object-Capability Subset of Java |
...
OBJ00-J. Limit the extensibility of classes and methods with invariants