Best implementation for hashCode method for a collection

后端 未结 20 3071
难免孤独
难免孤独 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条回答
  •  不知归路
    2020-11-22 02:42

    Just a quick note for completing other more detailed answer (in term of code):

    If I consider the question how-do-i-create-a-hash-table-in-java and especially the jGuru FAQ entry, I believe some other criteria upon which a hash code could be judged are:

    • synchronization (does the algo support concurrent access or not) ?
    • fail safe iteration (does the algo detect a collection which changes during iteration)
    • null value (does the hash code support null value in the collection)

提交回复
热议问题