Benefits of immutable objects in Java are:
1. Reference caching: References to immutable objects can be cached since there state is not going to change.throughout the program.
2. Easier to parallize: Since there are no conflicts between 2 objects, we can easily run operations in parallel.
3. Thread safe: Immutable objects are thread-safe so you will not have any synchronisation issues.
4. Hash key: Immutable objects are best as key Hash data structures.(Map keys and Set elements) since these typically do not change once created.
5. Easier to write code.
No comments:
Post a Comment