mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 08:51:02 +07:00
42 lines
977 B
HTML
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>
|