autobox « Boolean « Java Data Type Q&A





1. java: boolean instanceOf Boolean?    stackoverflow.com

I'm a bit confused: I have a function, that takes an Object as argument. But the compiler does not complain if I just pass a primitive and even recognizes a boolean ...

2. Booleans, conditional operators and autoboxing    stackoverflow.com

Why does this throw NPE

public static void main(String[] args) throws Exception {
    Boolean b = true ? returnsNull() : false; // NPE on this line.
    ...

3. Boolean != false    stackoverflow.com

In Java, you would usually say that if(someBool != false) is the same as if(someBool) But what if someBool is not of type boolean but Boolean, and its value is null?

4. Autoboxing and Booleans    forums.oracle.com

5. autoboxing booleans in comparisons    forums.oracle.com

Looking at the rules it seems to me the javac compiler behave inconsistently, or even more, IMHO, buggy. The jls rules state about unboxing only when one of the operands is of type Boolean. None of the operands is of type Boolean in my code. So none of the if statements should compile. B