Frage

I had a look at this but still not sure why or when should I use a Guava Immutablemap when I can have a java.util.Map and make it final.

Please can someone explain the advantages.

War es hilfreich?

Lösung

A final map just means that the reference (pointer) cannot change. You can still mutate the contents of the map (e.g., map.put(k, v), map.remove(k), etc.).

An immutable map is one that you cannot mutate the contents. You cannot add, remove, or clear the map.

For the many advantages of immutable collections, please see here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top