关于在Eclipse中生成serialVersionUID [英] About generated serialVersionUID in Eclipse
问题描述
如果我手动指定1L,2L,3L等等,这可能会造成任何问题吗?
Eclipse给出了一个选择添加生成的串行版本ID的选项,这个选项是否安全选择?
不,在以下两种情况下,不会造成任何问题:
- 您可以手动指定
- 您可以让Eclipse为其分配随机生成的值
- 您可以将它们全部保留
1L
为不同的类
串行的目的UID是禁止在不同版本中对同一类进行序列化和反序列化,特别是在没有向前兼容性的情况下(例如,新版本的类不能被以前的定义序列化/非串行化)。
这是一种很少发生的情况,特别是在使用不属于依赖于序列化的大型框架的自己的项目时。所以你可以安全地做任何你想要的。
你想要为同一个类有不同的序列的情况是当你更新一个类,你想要禁止它的序列化与以前的SAME类的声明。
Is there any way to generate serialVersionUID in Eclipse serially? By serially I want to mean that if one serializable class has serialVersionUID = 1L, then when I generate serialVersionUID of another class this will be serialVersionUID = 2L.
If I manually specify 1L, 2L, 3L and so on, will this can create any problem?
Eclipse gave an option to choose "Add generated serial version ID", is this option safe to choose?
No, it won't create any problem in any of your two circumstances:
- you can manually specify it incrementally
- you can let Eclipse assign them random generated values
- you can keep them all
1L
for different classes
The purpose of the serial UID is to forbid serialization and deserialization of same classes in different versions, especially when there is not forward compatibility (eg. new version of the class cannot be serialized/unserialized by a previous definition).
This is a circumstance that occurs really rarely, especially when working with your own project which are not part of big frameworks that rely on serialization. So you can safely do whatever you want.
The situation in which you want to have different serials for the same class is when you are updating a class and you want to forbid the serialization of it with a previous declaration of the SAME class.
这篇关于关于在Eclipse中生成serialVersionUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!