HashSet with two equals object?

前端 未结 4 1313
礼貌的吻别
礼貌的吻别 2020-12-19 17:47

I created an object HashSet, and the value is an object (Triple) which is my own class. But I get a strange thing, when there are two equal objects on my HashSet, is it poss

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 18:37

    You didn't override equals and hashCode in your class properly. Here's how to write it and test it :

    http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf

提交回复
热议问题