mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
update java inspection description
GitOrigin-RevId: 21e1d78a27b04d99b45400d05eec0c57a92f598b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
28f567ef14
commit
dba3752c8a
+36
-9
@@ -1,14 +1,41 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports classes which implement <b>java.lang.Comparable</b>
|
||||
which do not override <b>equals()</b>. If <b>equals()</b>
|
||||
is not overridden, the <b>equals()</b> implementation is not consistent with
|
||||
the <b>compareTo()</b> implementation. If an object of such a class is added
|
||||
to a collection such as <b>java.util.SortedSet</b>, this collection will violate
|
||||
the contract of <b>java.util.Set</b>, which is defined in terms of
|
||||
<b>equals()</b>.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Reports classes which implement <code>java.lang.Comparable</code>
|
||||
which do not override <code>equals()</code>. If <code>equals()</code>
|
||||
is not overridden, the <code>equals()</code> implementation is not consistent with
|
||||
the <code>compareTo()</code> implementation. If an object of such a class is added
|
||||
to a collection such as <code>java.util.SortedSet</code>, this collection will violate
|
||||
the contract of <code>java.util.Set</code>, which is defined in terms of
|
||||
<code>equals()</code>.
|
||||
<p>For example:</p>
|
||||
<pre><code>
|
||||
<b>class</b> Length <b>implements</b> Comparable<Length> {
|
||||
<b>private int</b> cm = 0;
|
||||
|
||||
@Override
|
||||
<b>public int</b> compareTo(@NotNull Length o) {
|
||||
<b>if</b> (cm == o.cm) <b>return</b> 0;
|
||||
<b>return</b> cm < o.cm ? -1 : 1;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied, the result looks like this:</p>
|
||||
<pre><code>
|
||||
<b>class</b> Length <b>implements</b> Comparable<Length> {
|
||||
<b>private int</b> cm = 0;
|
||||
|
||||
@Override
|
||||
<b>public int</b> compareTo(@NotNull Length o) {
|
||||
<b>if</b> (cm == o.cm) <b>return</b> 0;
|
||||
<b>return</b> cm < o.cm ? -1 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
<b>public boolean</b> equals(Object o) {
|
||||
<b>return</b> o <b>instanceof</b> Length && compareTo((Length) o) == 0;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user