Frage

Assuming that I have got completely different classes with different class names. Should I use different serialVersionUID in the classes?

If so, why is it necessary?

How does the JRE the deserialization exactly?

War es hilfreich?

Lösung

no you don't need different SUID (all classes can use 1 for it)

when an object is serialized the class identifier (package.name.ClassName) and SUID are both part of the header to identify the class the object belongs to and to ensure that there is no incompatibility between the writing side and the reading side

but when you change a class structurally (add/remove a field) you should set a new SUID for that class (during debugging you can let the JVM create a new one at runtime based on the .class file)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top