本文介绍了是否有理由使用真正的serialVersionUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题完全相同:

具有讽刺意味,回答者Michael Bogswardt也是。

Ironically, answered by Michael Bogswardt as well.

生成serialVersionUID的答案让我思考。有没有理由生成像eclipse和IDEA(或简单的serialver)这样的正确的serialVersionUID?或者插入1L一样好?

Michael Bogswardt's answer to generating a serialVersionUID got me thinking. Is there any reason to generate a proper serialVersionUID like eclipse and IDEA (or just plain serialver)? Or is plugging in a 1L just as good?

推荐答案

真正的serialVersionUID的唯一用途是用于后备兼容性。如果是新类,请使用您想要的任何编号系统。

The only use of a "real" serialVersionUID is for backword compatibility. If it is a new class, use whatever numbering system you want.

我个人认为使用简单的数字方案可以更容易地阅读和比较版本之间的数字变化。通过工具创建的哈希值对于机器来说是好的,但不是人类友好的。一个简单的一号编号方案对两者都很有用,毕竟机器并不关心这两种方式。

Personally I think using a simple number scheme will make it easier to read and compare changes of that number between versions. The hash value creating by the tooling is fine for a machine, but not human friendly. A simple one up numbering scheme works great for both, after all, the machine doesn't care one way or the other.

这篇关于是否有理由使用真正的serialVersionUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 19:13