来自日本的AD钙奶 2016-09-28 10:09 采纳率: 0%
浏览 953

FindBugs Report=>Object.equals() 使用的问题

..........................................................................

  • 写回答

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))

    评论

报告相同问题?