HashSet with two equals object?

前端 未结 4 1304
礼貌的吻别
礼貌的吻别 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:19

    I am having trouble understanding your question but hashCode() and equals() sematics are important only when you are planning to use an object as the key. And you cant have two objects evaluating to same hash in a Map...one will override the other

提交回复
热议问题