'equals()' called on itself
Reports calls to equals()
, compareTo()
or similar, that compare an object for equality with itself. The method contracts of these methods specify that such calls will always return true
for equals()
or 0
for compareTo()
. The inspection also checks calls to Objects.equals()
, Objects.deepEquals()
, Arrays.equals()
, Comparator.compare()
, assertEquals()
methods of test frameworks (JUnit, TestNG, AssertJ), Integer.compare()
, Integer.compareUnsigned()
and similar methods.
Note that in rare cases, the inspection may report equals()
calls that return false, because while the expressions on the both sides are the same, they produce separate objects, and comparison is performed on references, rather than on content. The simplest example is new Object().equals(new Object())
. In any case, such calls are suspicious, and likely something else was intended.
Example:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
EqualsWithItself- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection options
Here you can find the description of settings available for the 'equals()' called on itself inspection, and the reference of their default values.
- Ignore possible contract testing
Not selected
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |