immutable class in java | custom immutable class java | user defined immutable class java
What is an immutable class in Java?
Immutable objects are instances whose state doesn’t change after it has been initialized.
For example, String is an immutable class and once instantiated its value never changes
How to Create an immutable class in Java?
To create an immutable class in Java, you have to do the following steps.
1. Declare the class as final so it can’t be extended.
2. Make all fields private so that direct access is not allowed.
3. Don’t provide setter methods for variables.
4. Make all mutable fields final so that its value can be assigned only once.
5. Initialize all the fields via a constructor performing deep copy.
Immutable class with list as field of class.
my immutable class in java
own immutable class in java
custom immutable class in java
user defined immutable class
interview question immutable class in java
immutable class in java
Another Video :
Topic : Custom key object for HashMap | object HashMap key | custom object as key in hashmap | hashmap key
Link: https://www.youtube.com/watch?v=626jyt0yN4M&t=530s