问题描述
当类在Eclipse中实现Serializable时,我有两个选项:添加默认 serialVersionUID(1L)
或生成 serialVersionUID(3567653491060394677L)
。我认为第一个更酷,但很多时候我看到人们使用第二个选项。有没有理由生成 long serialVersionUID
?
When class implements Serializable in Eclipse, I have two options: add default serialVersionUID(1L)
or generated serialVersionUID(3567653491060394677L)
. I think that first one is cooler, but many times I saw people using the second option. Is there any reason to generate long serialVersionUID
?
推荐答案
至于我可以说,这只是为了与以前的版本兼容。这只有在您之前忽略使用serialVersionUID,然后进行了一项您知道应该是但会导致序列化中断。
As far as I can tell, that would be only for compatibility with previous releases. This would only be useful if you neglected to use a serialVersionUID before, and then made a change that you know should be compatible but which causes serialization to break.
请参阅了解更多详情。
这篇关于为什么生成长serialVersionUID而不是简单的1L?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!