Weird ternary nullpointer

Viewed 50

This little snippet causes NPE when data isn't foo nor bar.

Boolean baz = data == foo ? true : data == bar ? false : null

I'm guessing the compiler interprets the null as a null Boolean and tries to autounbox it, but why? Is it because there are true/false values present? If so, shouldn't they just be autoboxed instead? The variable is of type Boolean after all.

0 Answers
Related