是否有理由使用真正的serialVersionUID?

编程入门 行业动态 更新时间:2024-10-23 12:31:44
本文介绍了是否有理由使用真正的serialVersionUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题完全相同:

为什么生成long serialVersionUID而不是简单的1L?

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

Ironically, answered by Michael Bogswardt as well.

Michael Bogswardt 生成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?

本文发布于:2023-11-29 08:27:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有理由   serialVersionUID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!