执行如下(jdk1.6.0_31):
private static class ReverseComparator<T>
implements Comparator<Comparable<Object>>, Serializable {
// use serialVersionUID from JDK 1.2.2 for interoperability
private static final long serialVersionUID = 7207038068494060240L;
public int compare(Comparable<Object> c1, Comparable<Object> c2) {
return c2.compareTo(c1);
}
private Object readResolve() { return reverseOrder(); }
}
为什么要执行:
private static class ReverseComparator<T extends Comparable<T>>
implements Comparator<T>, Serializable {
// use serialVersionUID from JDK 1.2.2 for interoperability
private static final long serialVersionUID = 7207038068494060240L;
public int compare(T c1, T c2){
return c2.compareTo(c1);
}
...
}
它是否只是风格,还是有更深的理由?
EDIT:显示的来源代码来自Sun/Oracle jdk(jdk1.6.0_31)。