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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top