..........................................................................
2条回答 默认 最新
徐福记456 2016-09-30 17:08关注原文提示应该是这样:It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)).
重写compareTo有一定的风险,因为你不知道JDK内部做对象对比时,到底使用了compareTo还是equals。例如:在JAVA5 里,PriorityQueue.remove中使用了compareTo,但JAVA6中,PriorityQueue.remove使用了equals方法。
所以if判断条件应该改成这样: (x.compareTo(y)==0) == (x.equals(y))解决 无用评论 打赏 举报