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

When is UnsupportedOperationException Thrown in Java ?

How Will You Use Other Java Files of Your Application in JSP Code ...

What are the Differences Between a Checked and Unchecked Exceptio ...

How Will You Implement Error Page in JSP ?

What are the Rules of Method Overloading and Method Overriding in ...