Description of serialVersionUID in Java

Source: Internet
Author: User

To maintain version compatibility during serialization, that is, during version upgrade, deserialization still maintains the uniqueness of objects.
There are two generation methods:
One is the default 1L, for example, private static final long serialVersionUID = 1L;
One is to generate a 64-bit hash field based on the class name, Interface Name, member method, and attribute. For example:
Private static final long serialVersionUID = xxxxL;

When a class implements the Serializable interface, if serialVersionUID is not defined, Eclipse will provide this
The prompt function tells you to define it. Click the "warning" icon in the class in Eclipse, and Eclipse will
Two automatic generation methods are provided. If you do not want to define it, it is also set in Eclipse.
You can disable it as follows:
Window ==> Preferences ==> Java ==> Compiler ==> Error/Warnings ==>
Potential programming problems
Change the value of Serializable class without serialVersionUID to ignore.

If you do not consider compatibility issues, turn it off, but this function is good. If Serializable is implemented in any category, if serialVersionUID is not added, eclipse will give you a warning that this serialVersionUID is backward compatible for this type of Serializable.

If your class Serialized is stored on the hard disk, but then you change the field of the category (increase, decrease, or rename), when you Deserialize, an Exception will occur, this will cause incompatibility issues.

However, when the serialVersionUID is the same, it will Deserialize different fields with the default value of type to avoid incompatibility issues.

Author "loading"

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.