Best implementation for hashCode method for a collection

后端 未结 20 3412
难免孤独
难免孤独 2020-11-22 01:39

How do we decide on the best implementation of hashCode() method for a collection (assuming that equals method has been overridden correctly) ?

20条回答
  •  旧时难觅i
    2020-11-22 02:43

    If you use eclipse, you can generate equals() and hashCode() using:

    Source -> Generate hashCode() and equals().

    Using this function you can decide which fields you want to use for equality and hash code calculation, and Eclipse generates the corresponding methods.

提交回复
热议问题