什么是序列号? [英] what is a serial version id?

查看:174
本文介绍了什么是序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复什么是serialVersionUID,为什么要使用它?



现在使用Eclipse进行一些java工作。我的班级名称以黄色加下划线。我可以禁止警告或只是添加frickin序列号。



我不关心任何一种方式(或应该我?),但是这是什么序列号? / p>

谢谢

解决方案

它与Java序列化有关。 p>

当类的字段更改时,您将无法再次排序其他版本的类。如果你尝试,Java会抛出一个异常。



但是有时候,字段的更改不重要,你想说反序列化。为此,您可以定义此序列号。现在Java将使用该数字而不是反射来决定您的类定义是否不同。



最后,您可以通过定义自己的序列化函数来解决所有这些问题,实际上许多倡导者坚持你应该。


Duplicate What is a serialVersionUID and why should I use it?

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.

I dont care either way (or should i?), but what exactly IS this serial id?

thanks

解决方案

It has to do with Java serialization.

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.

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."

Finally, you can get around all this by defining your own serialization functions, and indeed many advocates insist that you should.

这篇关于什么是序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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