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

36 lines
1.0 KiB
HTML

<html>
<body>
Reports classes that implement <code>java.lang.Comparator</code>,
but do not implement <code>java.io.Serializable</code>.
<p>
If a non-serializable comparator is used to construct an ordered collection such
as a <code>java.util.TreeMap</code> or <code>java.util.TreeSet</code>, then the
collection will also be non-serializable. This can result in unexpected and
difficult-to-diagnose bugs.
</p>
<p>
Since subclasses of <code>java.lang.Comparator</code> are often stateless,
simply marking them serializable is a small cost to avoid such issues.
</p>
<p><b>Example:</b></p>
<pre><code>
class Foo implements Comparator { // warning
@Override
public int compare(Object o1, Object o2) {
/* ... */
}
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
class Foo implements Comparator, Serializable { // no warning here
@Override
public int compare(Object o1, Object o2) {
/* ... */
}
}
</code></pre>
<!-- tooltip end -->
</body>
</html>