Private Static final long serialversionuid = 1l;

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.