Advantages of immutable classes / object
- Immutable objects are automatically thread-safe, the overhead caused due to use of synchronisation is avoided.
- Once created the state of the immutable object can not be changed so there is no possibility of them getting into an inconsistent state.
- The references to the immutable objects can be easily shared or cached without having to copy or clone them as there state can not be changed ever after construction.
- The best use of the immutable objects is as the keys of a map.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.