我什么时候需要更改serialVersionUID? [英] When do I have to change the serialVersionUID?

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

问题描述

我知道我可以使用serialVersionUID来控制类的版本。我读到我可以添加或删除字段,类仍然兼容,它只使用默认值。

I know that I can use serialVersionUID to control the version of classes. And I read that I can then add or remove fields and the class will still be compatible, it will just use default values.

必须时我更改了serialVersionUID?

When must I change the serialVersionUID?

推荐答案

当对结构进行不兼容的更改时,理想情况下应更改serialVersionUID字段的值。班级。完整的不兼容更改列表在 noreferrer> Java对象序列化规范

The value of the serialVersionUID field is should ideally be changed when incompatible changes are made to the structure of the class. The complete list of incompatible changes is listed in the Java Object Serialization Specification.

为了进一步扩展,对类的不兼容更改将阻止反序列化机制创建对象的实例,因为流中的信息不会映射到当前的类定义。

To expand further, incompatible changes to a class will prevent the deserialization mechanism from creating an instance of the object, because there is information in the stream that does not map to the current class definition.

这篇关于我什么时候需要更改serialVersionUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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