This produces null pointer:
boolean treatNullAsFalse = false;
String what = null;
System.out.println(what == null ? (treatNullAsFalse ? false : null) : what.equals("1")); // NULL POINTER
This doesn't.
boolean treatNullAsFalse = false;
String what = null;
System.out.println(what == null ? (treatNullAsFalse ? false : null) : (Boolean)what.equals("1"));
Any help, why does the (Boolean) cast fix the issue? I thought ternary operators figure out return types at compile time, but here some unboxing is producing an NPE.