2 min read

Advantages of Immutability in Java

An immutable object is one whose state or data cannot change after construction. Common immutable objects from the JDK include Strings and Integers.

Making use of immutable objects provides several advantages, including:

When should immutability be used in your classes?

“Classes should be immutable unless there’s a very good reason to make them mutable….If a class cannot be made immutable, limit its mutability as much as possible.” —Joshua Bloch, author of Effective Java.

That being said, here are some guidelines for making a class as immutable as possible:

References: http://www.javapractices.com/topic/TopicAction.do?Id=29

← All posts