import java.util.*; class EmptyCollection { void testEmptyListAsSingleton() { List exceptions = Collections.emptyList(); do { try { System.out.println("foo"); } catch (Throwable e) { if (exceptions == Collections.emptyList()) { exceptions = new ArrayList<>(); } exceptions.add(e); // no immutable list is modified warning } } while (true); } void testEmptyMapField() { Map map = Collections.emptyMap(); if (map == Collections.EMPTY_MAP) {} if (map.equals(Collections.EMPTY_MAP)) {} if (map == Collections.EMPTY_SET) {} } void test() { List list = fill(new ArrayList()); for(String s : list) { System.out.println(s); } list = fill(Collections.emptyList()); if (list.isEmpty()) { } } void testAddToSet() { Set set = new HashSet<>(); if (set.add("1")) { System.out.println("added"); } } static List fill(List list) { list.add("foo"); return list; } void custom() { SomeDict dictionary = new SomeDict(); if (dictionary.contains("aaa")) {} } } class SomeDict extends ArrayList { public SomeDict() { add("aaa"); add("bbb"); } }