Keywords: serialversionuid serializable eclipse I recently upgraded eclipse to version 3.1, but many similar warnings (warnings) will be issued in problems for programs written according to my previous habits ):
Use automatic repair. eclipse will automatically add: Private Static final long serialversionuid = 1l; In fact, this problem does not affect the running of the program, but I can see that there is a warning in problems, it also shows that the code we write is still not standard. Not afraid. We have the Internet to check what is going on. The specific reason is also related to the serialversionuid in serialization. Serialversionuid is used to indicate the compatibility between different versions of the class. If you modify this class, you need to modify this value. Otherwise, errors will occur when the class serialized in the old version is restored. You can use the serialver.exe tool in the bincatalog of JDK to generate the serialversionuid. For test. Class, run the command: serialver Test To ensure the compatibility of the class version during deserialization, it is best to add the Private Static final long serialversionuid attribute to each class to be serialized. The specific values are defined by yourself. In this way, even if a class is modified after the corresponding object has been serialized, the object can still be correctly deserialized. Otherwise, if this attribute is not displayed, the JVM calculates the attribute value based on the class information. The calculation result of the modified class is often different from that of the modified class, this causes object deserialization to fail because the class version is incompatible. Another disadvantage of not displaying the definition of this property value is that it is not conducive to program porting between different JVMs. Because different compilers may implement different calculation policies for this attribute value, although the class is not changed, the JVM is different, there is still a problem that the class version is incompatible and cannot be correctly deserialized. The serialization class is not frequently required in my system, so to remove these warnings, make the following settings: Window-preferences-Java, set the serializable class without serialversionuid from warning to ignore. Then eclipse will re-compile the program, and the warning information will disappear. Summary: if we develop a large number of classes that require serialization, we 'd better restore them to the original settings. This ensures the system performance and robustness.
|