How to make HashMap work properly with custom key type?

后端 未结 3 2124
礼貌的吻别
礼貌的吻别 2020-12-11 17:10

I think my question is quite simple, however I couldn\'t find the solution so I decided to ask here. What i need is to make a HashMap with a custom Key type lik

3条回答
  •  余生分开走
    2020-12-11 17:21

    You must implement properly equals and hashCode on the Pair class.

    The HashMap uses these methods to differentiate and hash the key class.

提交回复
热议问题