import java.util.*; import com.google.common.collect.ImmutableSet; class OverwrittenKey { void fillMap(Map map) { map.put("a", 1); map.put("b", 2); map.put("c", 3); map.put("d", 4); map.put("a", 5); map.put("a", 6); map.put("e", 7); map.put("f", 8); map.put("c", 9); } void fillSet(HashSet set, HashSet set2) { set.add(5234); set.add(5235); set.add(3452); set.add(3256); set.add(4635); set.add(4635); set.add(3252); set.add(2352); set.add(5253); set.add(5235); set.add(2145); set2.add(2145); set2.add(2); set2.add(345); set2.add(2); } enum Test { A,B,C,D,E } Map map = new HashMap() {{ put(Test.A, "a"); put(Test.B, "b"); this.put(Test.C, "c"); put(Test.C, "d"); put(Test.E, "e"); }}; void java9() { Set set = Set.of("a", "b", "c", "a"); Map map = Map.of("a", "a", "b", "b", "c", "b", "b", "d"); Map map2 = Map.ofEntries(Map.entry("a", "a"), Map.entry("b", "b"), Map.entry("c", "b"), Map.entry("b", "d")); } enum X { A, B, C } void enumSetOf() { EnumSet xx = EnumSet.of(X.A, X.B, X.A, X.C); System.out.println(xx); } void guavaImmutableSetOf() { ImmutableSet s = ImmutableSet.of(-10., 1d, -10.0); System.out.println(s); } void testParameter(Map map, String key) { map.put(key, "k1"); map.put(key, "k2"); } void localClass() { class X extends HashMap { class Y { void test() { put("a", "b"); put("a", "c"); } } } } void testFallthrough(Map map, int id) { switch(id) { case 1: map.put("foo", "bar"); case 2: map.put("foo", "baz"); default: map.put("foo", "qux"); } } void testNoFallthrough(Map map, int id) { switch(id) { case 1: map.put("foo", "bar"); break; case 2: map.put("foo", "baz"); break; default: map.put("foo", "qux"); break; } } void differentQualifiers(Set set) { set.add(h1.KEY); set.add(h2.KEY); } KeyHolder h1 = new KeyHolder(1); KeyHolder h2 = new KeyHolder(2); static class KeyHolder { final int KEY; KeyHolder(int k) {KEY = k;} } }