486c0a061c05a47b962f9a3ead7083081550a837

Set, Map and Vector have an immutable version, a version of the object that you cannot change.

Immutable objects can be cached more aggressively because we know for sure that they will not change its state. They are also thread safe (yes, I’ll talk about threads within the next few days). But the most obvious reason is simplicity. They are easier to understand and predict.

If you design a card game, you could have each card being a immutable object since you know the cards are not going to change their values or suits… You will, however, never encounter a situation where you need to use immutable objects. You could easily design the card game with mutable objects.

More about immutable objects in the Happyr developer blog.