I have to compare two Boolean
wrappers with each other. As a result I want to know if they are equal or not.
This is what I came up with:
public static boolean areEqual(final Boolean a, final Boolean b) {
if (a == b) {
return true;
}
if (a != null && b != null) {
return a.booleanValue() == b.booleanValue();
}
return false;
}
Is there a better and/or shorter way to correctly compare two Boolean
wrappers for equality?
First I wanted to use Object.equals()
or Boolean.compareTo()
but both ways could end up in a NullPointerException
, right?
Maybe there is something that I don't see here, that's why I'm asking.