Why should a Comparator implement Serializable?

前端 未结 5 488
陌清茗
陌清茗 2021-02-02 06:46

New to Java. Learning it while working on an Android app. I am implementing a Comparator to sort a list of files and the android docs say that a Comparator should implement Seri

5条回答
  •  -上瘾入骨i
    2021-02-02 07:36

    This should help you out : http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html

    Note: It is generally a good idea for comparators to 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.

提交回复
热议问题