问题描述
Java编译器警告:可序列化类[*****]不声明静态最终的serialVersionUID类型为long。
为什么?如何解决?
这个解释得相当好:
您可以通过添加
$来修复错误b$ b
private static final long serialVersionUID = 7526472295622776147L; //唯一ID
到班级。
进一步阅读:
- (计算器)
附注:如果你正在使用Eclipse,如果你(而且没有其他人)曾经计划过序列化您的课程,您也可以通过转到
窗口→首选项→Java→编译器→错误/警告
并在Serializable Class without serialVersionUID上选择忽略。
Java compiler warning: The serializable class [*****] does not declare a static final serialVersionUID field of type long.
Why? How to fix it?
This is explained fairly well here:
You fix the error by adding
private static final long serialVersionUID = 7526472295622776147L; // unique id
to the class.
Further reading:
- java.io.Serializable
- Why should I bother about serialVersionUID? (stackoverflow)
A side note: If you're using Eclipse and if you (and no one else) ever plan to serialize your classes, you can also suppress the error by going to
Window → Preferences → Java → Compiler → Errors/Warnings
and select "Ignore" on "Serializable Class without serialVersionUID".
这篇关于“声明静态最终serialVersionUID”是什么?警告意味着如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!