HashSet with two equals object?

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

    You need to be sure to implement hashCode() as well, and when two Triples are equal, their hashCodes must also be equal. If you don't do that, you will get strange behavior.

提交回复
热议问题