netjs

How to create immutable class in Java

Immutable class, as the name suggests, is a class whose object can’t be modified in anyway once created. Once an object of the immutable class is created and initialized the content of any field of that object can’t be changed in anyway and remains same throughout the life of the object. If there are methods that should modify the content in some way then a new object is created with the modified content and returned, original...