I F3'd into this for no particular reason, and was surprised to see this method implemented as follows:
public static boolean isTrue(Boolean bool) {
if (bool == null) {
return false;
}
return bool.booleanValue() ? true : false;
}
Why not?
public static boolean isTrue(Boolean bool) {
if (bool == null) {
return false;
}
return bool.booleanValue();
}
It doesn't really matter, so I wondered is there some benefit to it? Readability is a weak enough argument, I consider this to be noise. Unless there is some other benefit that I am missing.
The isTrue static method of the BooleanUtils class can be used to check if the passed Boolean value is equal to true .
public class BooleanUtils extends Object. Operations on boolean primitives and Boolean objects. This class tries to handle null input gracefully. An exception will not be thrown for a null input. Each method documents its behavior in more detail.
I can't find any justifiable reason.
The API specification for Java says:
public boolean booleanValue()
Returns the value of this Boolean object as a boolean primitive.
So if our bool object is:
Boolean bool = new Boolean(true);
This is equivalent:
bool.booleanValue() == true;
The ternary comparator here is redundant and decrease the readability.
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