Files
openide/java/java-impl/resources/inspectionDescriptions/EqualsAndHashcode.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

42 lines
977 B
HTML

<html>
<body>
Reports classes that override the
<code>equals()</code> method but do not override the
<code>hashCode()</code> method or vice versa, which can potentially lead to problems
when the class is added to a <code>Collection</code> or a <code>HashMap</code>.
<p>The quick-fix generates the default implementation for an absent method.</p>
<p>Example:</p>
<pre><code>
class StringHolder {
String s;
@Override public int hashCode() {
return s != null ? s.hashCode() : 0;
}
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
class StringHolder {
String s;
@Override public int hashCode() {
return s != null ? s.hashCode() : 0;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof StringHolder)) return false;
StringHolder holder = (StringHolder)o;
if (s != null ? !s.equals(holder.s) : holder.s != null) return false;
return true;
}
}
</code></pre>
</body>
</html>