eclipse 什么是串行版本 ID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/615181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is a serial version id?
提问by Jason Cohen
Duplicate What is a serialVersionUID and why should I use it?
重复什么是 serialVersionUID,为什么要使用它?
Using Eclipse for some java work right now. My class name is underlined in yellow. I can either suppress the warning or just add the frickin serial id.
现在使用 Eclipse 进行一些 Java 工作。我的班级名称带有黄色下划线。我可以取消警告或只添加 frickin 序列号。
I dont care either way (or should i?), but what exactly IS this serial id?
我不在乎任何一种方式(或者我应该关心?),但是这个序列号到底是什么?
thanks
谢谢
回答by Jason Cohen
It has to do with Java serialization.
它与Java序列化有关。
When the fields of a class changes, you can no longer unserialize other versions of the class. If you try, Java will throw an exception.
当类的字段发生变化时,您不能再对类的其他版本进行反序列化。如果您尝试,Java 将抛出异常。
However sometimes the change in fields don't matter and you want to say "unserialize anyway." To do that, you define this serial number. Now Java will use that number rather than reflection to decide whether your class definition is "different."
然而,有时字段的变化并不重要,您想说“无论如何反序列化”。为此,您需要定义此序列号。现在 Java 将使用该数字而不是反射来确定您的类定义是否“不同”。
Finally, you can get around all this by defining your own serialization functions, and indeed many advocates insist that you should.
最后,您可以通过定义自己的序列化函数来解决所有这些问题,事实上,许多倡导者坚持认为您应该这样做。