I am trying for null check like below
if (isTrue == null)
compile error says : "The operator == is undefined for the argument type(s) boolean"
Please help, how to do null check.
Thanks
You can't do null
check on primitive types. boolean
is a primitive type.
If you absolutely need to represent a null
value with a boolean
variable, you need to use the wrapper class java.lang.Boolean
.
So, your example would be:
Boolean isTrue;
isTrue = null; // valid
isTrue = true; // valid
isTrue = false; // valid
if (isTrue == null) {
// valid!
}
Here's the WIKIPEDIA entry for primitive wrapper classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With