문제

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