TestImmutable.java 364 B

12345678910111213
  1. import java.util.*;
  2. public class TestImmutable {
  3. public static void main(String[] args) {
  4. HashMap<Integer, Integer> map = new HashMap<>();
  5. Map<Integer, Integer> immutableMap = Collections.unmodifiableMap(map);
  6. try {
  7. immutableMap.put(0, 0);
  8. } catch (Exception e) {
  9. e.printStackTrace();
  10. }
  11. }
  12. }