Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The clone() method returns a copy of the original object that reflects the state of the original object at the moment of cloning. This new object can be used without exposing the original object; because the caller holds the only reference to the newly cloned instance, the instance fields cannot be changed without the caller's cooperation. This use of the clone() method allows the class to remain securely mutable. (See guideline OBJ10OBJ08-J. Provide mutable classes with copy functionality to allow passing instances to untrusted code safely.)

The Point class is declared final to prevent subclasses from overriding the clone() method. This enables the class to be suitably used without any inadvertent modifications of the original object. This solution also complies with guideline OBJ10OBJ08-J. Provide mutable classes with copy functionality to allow passing instances to untrusted code safely.

...