Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top