Serialversionuid is used to indicate the compatibility between different versions of the class.
To put it simply, Java's serialization mechanism verifies version consistency by judging the serialversionuid of the class at runtime. During deserialization,
The JVM compares the serialversionuid In the byte stream with the serialversionuid of the local object (class,
If they are the same, they are considered to be consistent. deserialization can be performed. Otherwise, an exception occurs when the serialization version is inconsistent.
When the object (class) implementing the java. Io. serializable interface does not explicitly define a variable named serialversionuid whose type is long,
The Java serialization mechanism automatically generates a serialversionuid Based on the compiled class for the serialization version comparison. In this case,
Only the class generated by the same compilation will generate the same serialversionuid.
If we do not want to forcibly divide the software version by compiling, that is, the entity implementing the serialization interface can be compatible with the previous version. If the class is not changed, we need to explicitly define a class named
Serialversionuid: A long variable. serialized entities that do not modify the value of this variable can be serialized or deserialized to each other.