FindBugs 플러그인1을 통해 찾은 버그, Comparator doesn't implement Serializable
알아야 할 것이 많아질수록 오히려 자바 기초는 뒷전이다. 예전에 Agile Java Network이란 스터디를 만든 것도 그 출발은 이러한 경각심에서다.2 하여간 FindBugs 플러그인을 써보니 다시 기초를 돌아본다.
FindBugs 왈,
알아야 할 것이 많아질수록 오히려 자바 기초는 뒷전이다. 예전에 Agile Java Network이란 스터디를 만든 것도 그 출발은 이러한 경각심에서다.2 하여간 FindBugs 플러그인을 써보니 다시 기초를 돌아본다.
FindBugs 왈,
This class implements the
Comparator interface. You should
consider whether or not it should also implement the Serializable
interface. If a comparator is used to construct an ordered collection such as a
TreeMap, then the TreeMap will be serializable only if
the comparator is also serializable. As most comparators have little or no
state, making them serializable is generally easy and good defensive
programming. 하여 Java API를 찾아보니
Note: It is generally a good idea for comparators to also implement
java.io.Serializable, as they may be used as ordering methods in
serializable data structures (like
TreeSet, TreeMap). In
order for the data structure to serialize successfully, the comparator (if
provided) must implement Serializable.
