Versions Compared

Key

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

Recall that immutability offers several benefits such as thread-safety, prevention against inadvertent modification of fields and malicious tampering. Class invariants and state of immutable objects are always consistent with the their requirements and , so no defensive copying is necessary. However, sometimes it is not possible to make sensitive classes immutable. Fortunately, there is a mechanism that allows code to expose mutable classes to untrusted code by granting read-only access. This is largely achieved through unmodifiable wrappers. For example, in the Collection classes a set of wrappers allow clients to observe an unmodifiable view of the particular Collection object.

...