Java - Create Immutable Class
How to Create Immutable Class in Java ?
To create immutable class we need to follow certain steps,
To create immutable class we need to follow certain steps,
- Declare the class as Final
- Make all fields as Private & Final
- Don't Create Setter for any fields
- Initialize all fields via constructor
- Perform cloning of objects in the getter methods to return a copy rather than returning the actual object reference.
Comments
Post a Comment