The role of serialVersionUID:
In order to maintain version compatibility during serialization, deserialization still maintains the uniqueness of the object when the version is upgraded.
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, etc., such as:
private static final long serialVersionUID = xxxxL;
When your class implements the Serializable interface, if serialVersionUID is not defined, Eclipse will provide this
The prompt function tells you to define it. In Eclipse, click the warning icon in the class, and Eclipse will
Two generation methods are automatically given. If you don't want to define it, you can also
You can turn it off and set it as follows:
Window ==> Preferences ==> Java ==> Compiler ==> Error/Warnings ==>
Potential programming problems
Just change the warning of Serializable class without serialVersionUID to ignore.
If you don't consider compatibility issues, turn it off, but it is good to have this function. As long as any category implements the Serializable interface, Eclipse will give you a warning prompt if serialVersionUID is not added. This serialVersionUID is for The class Serializable is backwards compatible.
If your class is Serialized and saved to the hard disk, but later you change the field of the class (add or reduce or rename), an Exception will appear when you Deserialize, which will cause incompatibility problems.
But when the serialVersionUID is the same, it will Deserialize different fields with the default value of type, which can avoid incompatibility problems.