java.util.Objects.equals()
, which is available since JDK 1.7.
For example:
a != null && a.equals(b)
If a.equals(b)
isn't preceded with a != null
, replacing it with Objects.equals(a, b)
still makes sense, but slightly changes the semantics. For the cases where only equivalent replacement is needed, there's
the check box Report only null safe 'equals' calls to enforce that.
This inspection only applies to projects and modules configured to use a language level of 7 or higher.