Re: HashMaps, hashcodes, equals, and Serialization



"Siam" <siamraf@xxxxxxxxx> wrote in message
news:1167488849.406980.57250@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
?

2) The contract for hashcode, as written in the API, states "This
integer [the hashcode] need not remain consistent from one execution of
an application to another execution of the same application." Will this
cause complications for when my articles and the hashmap are
serialized, and later deserialized on another execution of my
application? In that, surely if the hashcode is used in determining
where in the table a certain Article object is placed, then if the
hashcode for the Article (when deserialized) changes on another
execution of the application, would the hashmap still be able to find
the Article in its previous place? Or does
serialization/deserialization maintain the hashcode of the object?

During deserialization, the keys are rehashed and the hash chains rebuilt
from scratch, so the new hash table is correct even though the hash values
have changed.


.



Relevant Pages

  • Re: fast hashCode for an array.
    ... > The hashCode needs to provide the same value for objects that are ... provided no information used in equals comparisons ... execution of an application to another execution of the same application. ... calling the hashCode method on each of the two objects must produce the same ...
    (comp.lang.java.programmer)
  • Re: Hashcode - SHA256Managed
    ... > eine Datenmenge von 257Bit muss automatisch zur Kollision kommen. ... Wenn ich von EINE Dateimit SHA256 einen Hashcode erzeuge, ... Und bei 2^256 ist sehr unwahrscheinlich das zwei unterschiedliche Objekte den gleichen Hash haben. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: =?UTF-8?B?4oCYcGVyZm9ybWFuY2XigJkgb2YgYmFzaWMgb3BlcmF0aW9ucw==?=
    ... Hash: SHA1 ... Patricia Shanahan schreef: ... implement equals and hashCode. ...
    (comp.lang.java.programmer)
  • Deserialization bug: NullPointerException thrown during HashMap.hash()
    ... NullPointerException thrown when deserializing. ... deserialization, the object sent in had a non-null value in that field. ... tend to be essential to a hashCode() override!). ... public void setASet{ ...
    (comp.lang.java.programmer)
  • Re: Generate hash code
    ... The hashcode is not the same as the key; the hashcode is just used to ... requests both an equality method and a hash method. ... then takes the mod of this with the bucket count to ... checking Equals, or possibly first checking the hash of each item and then ...
    (microsoft.public.dotnet.languages.csharp)