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

What are the Popular Implementations of Deque in Java ?

What is the Use of Jsp:useBean in JSP ?

What are the Differences Between a List and Set Collection in Jav ...

What are the Advantages of Using JSP in Web Architecture ?

What is Observer Design Pattern in Java ?