Inspectopedia
 
2024.3

Covariant 'equals()'

Warning
New
Last modified: 03 December 2024

Reports equals() methods taking an argument type other than java.lang.Object if the containing class does not have other overloads of equals() that take java.lang.Object as its argument type.

A covariant version of equals() does not override the Object.equals(Object) method. It may cause unexpected behavior at runtime. For example, if the class is used to construct one of the standard collection classes, which expect that the Object.equals(Object) method is overridden.

Example: