import java.util.*; import org.jetbrains.annotations.*; public class MutabilityInferred { @Nullable static List getListNullOrImmutable(int x) { if(x == 0) return null; return Collections.singletonList("foo"); } static List getListImmutable(int x) { if(x == 0) return Collections.singletonList("bar"); return Collections.singletonList("foo"); } static List getListImmutableOrMutable(int x) { if(x == 0) return new ArrayList<>(); return Collections.singletonList("foo"); } static native List getListUnknown(int x); @Nullable static List getListVar(boolean b) { List list = getListUnknown(0); if (list != null) return list; if (b) return Collections.singletonList("xyz"); return null; } static Map getMap() { return Map.of("foo", "bar"); } static Map.Entry getEntry() { return Map.entry("foo", "bar"); } void test() { getListNullOrImmutable(0).add("a"); getListImmutable(0).add("b"); getListImmutableOrMutable(0).add("c"); getListVar(false).add("d"); getMap().put("baz", "qux"); getEntry().setValue("qux"); } }