Creating an immutable class:-
- Declare the class as final.
Features:-
- They are thread safe automatically so no need to synchronize.
- Once created the state of the object can not be changed so there is no possibility of going to inconsistent state.
- The reference can be easily shared and cached without the need to copy them
- They can be used as keys for the map
No comments:
Post a Comment