...
This compliant solution provides a clone()
method in the class and does not require the elimination of the setter method. The clone()
method returns a copy of the original object. This new object can be freely used without affecting the original object. Using the clone()
method allows the class to remain mutable. (OBJ10-J. Provide mutable classes with a clone method copy functionality to allow passing instances to untrusted code safely)
...
The class is declared final
to prevent subclasses from overriding the clone()
method. This enables the class to be accessed and used, while preventing the fields from being modified, and complies with OBJ10-J. Provide mutable classes with a clone method copy functionality to allow passing instances to untrusted code safely.
...