equals-hash-code
What it does
Section titled “What it does”Reports a class that declares boolean equals(Object) and does not declare hashCode().
Why it matters
Section titled “Why it matters”Objects that are equal must have the same hash code. Without an own hashCode the one of Object is used, so two equal objects land in different buckets and a HashMap or HashSet does not find them.
To fix, declare hashCode() from the same fields as equals.
Example
Section titled “Example”class A { public boolean equals(Object o) {... }
...Configuration
Section titled “Configuration”java: lint: rules: equals-hash-code: warn # off, warn (default), errorSuppress one line with sudsy-disable-next-line equals-hash-code in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| checkstyle | EqualsHashCode |
partial | Only equals without hashCode, not the reverse. |