SE450: Taxonomy: Guidelines for Immutable Data Classes [56/63] Previous pageContentsNext page

An instance of an immutable data class is immutable if the objects passed into the constructor never change.

Pair p1 = new Pair("dog", "cat");
StringBuilder b2 = new StringBuilder("dog");
Pair p2 = new Pair(b2, "cat");
Pair p3 = new Pair(new StringBuilder("dog"), "cat");

Note that p1 is immutable, but p2 is mutable.

What about p3?

Hashcode Links

Java Practices article

Apache HashCodeBuilder

Vipan Singla's comments on hashCode

Brian Goetz's comments on hashCode

Mark Roulo's comments on hashCode

Previous pageContentsNext page