英文:
Class Serialization in Java: compatibility after changing field name or getter/setter name
问题
在Java中,如果我们修改一个可序列化类的成员的名称(仅名称)和/或其getter或setter,是否会导致兼容性错误?
英文:
Suppose we have a Serializable class in Java and we change the name (only the name) of a member of the class and/or its getter or setter, can it cause compatibility errors?
答案1
得分: 2
Renaming a field is equivalent to deleting which falls under the section Incompatible Changes in the specifications.
> 5.6.1 Incompatible Changes
不兼容的类更改是指那些无法保证互操作性的更改。在演化类时可能发生的不兼容更改包括:
>Deleting fields - If a field is deleted in a class, the stream written will not contain its value.
删除字段 - 如果在类中删除了字段,则写入的流将不包含其值。
When the stream is read by an earlier class, the value of the field will be set to the default value because no value is available in the stream.
当早期类读取流时,字段的值将设置为默认值,因为在流中没有可用的值。
However, this default value may adversely impair the ability of the earlier version to fulfill its contract.
然而,此默认值可能会对早期版本履行其合同的能力产生不利影响。
英文:
Renaming a field is equivalent to deleting which falls under the section Incompatible Changes in the specifications.
> 5.6.1 Incompatible Changes
Incompatible changes to classes are those changes for which the guarantee of interoperability cannot be maintained. The incompatible changes that may occur while evolving a class are:
>Deleting fields - If a field is deleted in a class, the stream written will not contain its value. When the stream is read by an earlier class, the value of the field will be set to the default value because no value is available in the stream. However, this default value may adversely impair the ability of the earlier version to fulfill its contract.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论