HashCodeToString
Classes that override hashCode should also consider overriding toString.

Severity
SUGGESTION
Tags
FragileCode
Has Fix?

The problem

Classes that override hashCode() should consider also overriding toString() with details to aid debugging and diagnostics, instead of relying on the default Object.toString() implementation.

Object.toString() returns a string consisting of the class’ name and the instances’ hash code. When hashCode() is overridden this can be misleading, as users typically expect this default toString() to be (semi)unique per-instance, especially when debugging.

See also MoreObjects.toStringHelper()

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("HashCodeToString") to the enclosing element.