Given the following code:
boolean c = true;
boolean d = true;
boolean b = c ? null : d;
System.out.println(b);
Why does the compiler not complain here? Variable b is a primitive datatype, shouldn't the null produce an error message like "Type mismatch: cannot convert from null to boolean"?
My best guess is, that there's some autoboxing going on? I saw this code in a project, but I would love to know the exact reason behind this...
EDIT1: As noted below by Mena, this code produces a NullPointer during runtime
EDIT 2: the following form also compiles without error:
boolean c = false;
boolean d = true;
boolean b = c ? null : d;
System.out.println(b);
EDIT 3: When trying to compile with compiler level 1.4, this will NOT compile, but produce an error:
Incompatible conditional operand types null and boolean.
So auto-boxing would make sense, as it was introduced with 1.5?