How can we make class immutable .
InstructorYogesh Chawla Replied on 26/10/2020
These are the steps to be followed.
Declare the class as final so it can't be extended.
Make all fields private and final so the direct access is not allowed.
Don't provide setter methods for variables
Initialize fields via constructor performing deep copy.
Perform cloning of objects in the getter methods to return a copy rather than returning the actual object reference.
Rest we have explained everything as part of topic 'Immutable Class/Object, Wrapper Class/Object, String, StringBuffer and StringBuilder'
Please do check that too.