Comparator and equals()

后端 未结 11 2027
终归单人心
终归单人心 2020-12-16 17:27

Suppose I need TreeSet with elements sorted with some domain logic. By this logic it doesn\'t matter order of some elements that doesn\'t equal so compare metho

11条回答
  •  生来不讨喜
    2020-12-16 18:06

    Very interesting question. As far as I understand your problem is duplicate elements.

    I think that if o1.equals(o2) their hash codes might be equal too. It depends on the implementation of hashCode() in your Foo class. So, I'd suggest you to use System.identityHashCode(x) instead.

提交回复
热议问题