Search code examples
javaserializationhashcodeserialversionuid

Hashcode as serialVersionUid


I read in an article that the default serialVersionUid provided by JVM is the hashcode of an object. If we don't override the hashcode method in a class, how will the hashcode be computed during deserializatio as normally hashcode is the memory address of object?


Solution

  • I read in an article that the default serialVersionUid provided by JVM is the hashcode of an object.

    That is incorrect. (Either the article is incorrect, or you misread / misunderstood it.)

    The default serial version UID for a serializable class is totally unrelated to the hashCode.

    The algorithm for generating the defaut serial version UID is described here:

    Basically, it creates an SHA-1 hash from the classes name, modifiers, interface names, and the signatures for its fields, constructors and methods. Then it takes the first 8 bytes of the hash and assembles them into a long.