import java.util.*; class Test { void test(boolean b) { Set set1 = new HashSet<>(); Set set2 = new HashSet<>(); Set activeSet = b ? set1 : set2; activeSet.add("foo"); if (set1.isEmpty()) { if (b) {} } } }