- Since Immutable objects won't change their state, so no concurrency over head required.
- They reduce errors: mutable objects are vulnerable to being changed when you don't expect it.
- They can be safely shared (i.e. multiple references to the same object) which can reduce memory consumption and improve cache utilisation.
Note
: The only real disadvantage of
immutable classes is that they require a separate object for each
distinct value.
No comments:
Post a Comment