Due to the similar name with the methods Object.toString
, Object.hashCode
and Object.equals
, there is a
significant likelihood that a developer intended to override one of these methods but made a spelling error.
Even if no such error exists and the naming was done on purpose, these method names can be misleading. Readers might not notice the difference, or if they do, they may falsely assume that the developer made a mistake.
If you intended to override one of the methods Object.toString
, Object.hashCode
, or Object.equals
, correct
the spelling. Also, you should add the @Override
modifier, which causes a compiler error message in case the annotated method does not
override anything.
If the naming was done on purpose, you should rename the methods to be more distinctive.
public int hashcode() { /* ... */ } // Noncompliant public String tostring() { /* ... */ } // Noncompliant public boolean equal(Object obj) { /* ... */ } // Noncompliant
@Override public int hashCode() { /* ... */ } // Compliant @Override public String toString() { /* ... */ } // Compliant @Override public boolean equals(Object obj) { /* ... */ } // Compliant