I have
Boolean condition;
public Boolean isCondition() { return condition; }
Is the following usage of this method then allowed, as with a primitive,
if (isCondition())
{
//...
}
I would use that for primitives but not sure about the class. Does it need to be checked for NULLs? Do I need to getBooleanValue() first?
Yes, you can use any boxed primitive (in your case, Boolean) as a primitive itself; namely, your example would work if you could guarantee that condition was set to a non-null value.
The caveat here is that if any of the boxed primitives themselves are null, you will get a NullPointerException when unboxing them. If you have the possibility of that value being null, you should re-evaluate why you're using the boxed primitive in the first place. It may be better to use the unboxed primitive (in your case, boolean) instead.
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