Since Java 7 you can use the static method java.util.Objects.equals(Object, Object)
to perform equals checks on two objects without caring about them being null
.
If both objects are null
it will return true
, if one is null
and another isn’t it will return false
. Otherwise it will return the result of calling equals
on the first object with the second as argument.