1.Warning
The serializable class XXX does not declare a static final serialVersionUID field of type long
2. Causes:
When you implement the serializable interface for a class, if you do not define serialVersionUID, eclipse will provide this prompt function to tell you to define it
3. SerialVersionUID function:
in order to maintain version compatibility during serialization, that is to say, during version upgrade, deserialization still keeps the uniqueness of the object
4. SerialVersionUID generation method:
You can write one at will. In eclipse, it generates one for you in two ways
1. One is the default 1L, for example: private static final long serialVersionUID = 1L
2. One is to generate a 64 bit hash field according to the class name, interface name, member method and attribute
For example: private static final long serialVersionUID = – 8940196742313994740l; Or something
solution:
click the warning icon in the class in eclipse, and eclipse will automatically give two generation methods, as described above
If you don’t want to define it, you can also turn it off in eclipse settings as follows:
window = = > Preferences==> Java ==> Compiler ==> Error/Warnings ==> Potential programming problems
change the warning of serializable class without serialVersionUID to ignore
If you don’t consider the compatibility problem, turn it off. However, it’s good to have this function. As long as any class implements the serializable interface, eclipse will give you a warning prompt if you don’t add the serialVersionUID. This serialVersionUID is to make the serializable class backward compatible
If your class serialized is saved on the hard disk, but later you change the field of the class (increase or decrease or rename), when you deserialize, an exception will appear, which will cause incompatibility
However, when the serialVersionUID is the same, it will deserialize different fields with the default value of type, which can avoid the problem of incompatibility