import java.util.*; import org.jetbrains.annotations.*; public class EmptySingletonMap { void testMixed(int x) { Collection strings; if(x > 10) { strings = Collections.singleton("foo"); } else if(x > 6) { strings = Collections.emptyList(); } else if(x > 2) { strings = Collections.singletonList("bar"); } else { strings = Arrays.asList("a", "b", "c"); } if(strings.size() >= 2 && x > 3) { System.out.println("never"); } } void testMap(boolean b) { Map map; if (b) { map = Collections.emptyMap(); } else { map = Collections.singletonMap("a", "b"); } if(b && map.isEmpty()) { System.out.println("true"); } if(!b && map.size() == 1) { System.out.println("??"); } } @Contract(pure = true) static Map newMap() { return new HashMap<>(); } void testDoubleEmpty() { Map m1 = newMap(); Map m2 = newMap(); fill(m1, m2); if(m1.isEmpty() && m2.isEmpty()) { System.out.println("both empty"); } } void testNonEqual() { if(EmptySingletonMap.newMap() == EmptySingletonMap.newMap()) { System.out.println("who knows"); } } native void fill(Object m1, Object m2); }