Do I need to implement hashCode() and equals() methods?

前端 未结 4 961
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 07:47

If I have a map and an object as map key, are the default hash and equals methods enough?

class EventInfo{

    private String name;
    private Map

        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 07:59

    Yes, you need them else you won't be able to compare two EventInfo (and your map won't work).

提交回复
热议问题