关于在Eclipse中生成serialVersionUID [英] About generated serialVersionUID in Eclipse

查看:511
本文介绍了关于在Eclipse中生成serialVersionUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Eclipse中连续生成serialVersionUID?通过串行我想意味着如果一个可序列化的类有serialVersionUID = 1L,那么当我生成另一个类的serialVersionUID时,这将是serialVersionUID = 2L。



如果我手动指定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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆