How Will You Make an Object Immutable in Java ?

To make an object immutable follow these two rules. One, do not use any setter methods that can change the fields of your class. Two, make the fields final. By following these rules, the member variables cannot be changed after initialization. This will ensure that member variables of an Object do not change. And thus the Object will be considered Immutable.



You May Interest

Enumeration and Iterator, Which One Has Better Performance in Jav ...

What is the Difference Between Expression and Scriptlet in JSP ?

What is a Directive in JSP ?

What is the Difference Between pass by reference and pass by valu ...

When Will You Use Strategy Design Pattern in Java ?