Question

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?

Était-ce utile?

La solution

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)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top