1.
They are less prone to error and are more secure.
2.
Immutable classes are easier to design, implement, and use than mutable
classes.
3.
Immutable objects are thread-safe so there are no synchronization issues.
4.
Immutable objects are good Map keys and Set elements, since these typically do
not change once created.
5. Immutability
makes it easier to write, use and reason about the code (class invariant is
established once and then unchanged).
6.
Immutability makes it easier to parallelize program as there are no conflicts
among objects.
7.
The internal state of program will be consistent even if you have exceptions.
8.
References to immutable objects can be cached as they are not going to change. (i.e
in Hashing it provide fast operations).
References:
https://en.wikipedia.org/wiki/Immutable_object
References:
https://en.wikipedia.org/wiki/Immutable_object
No comments:
Post a Comment