Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top