瞬态变量继承和子类被序列化 [英] Transient variable inherited and subclass is serialized

查看:57
本文介绍了瞬态变量继承和子类被序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果继承了 Serializable 类的瞬态变量,并且我更改了子类中变量的值.

If transient variable from a Serializable class is inherited and if i change the value of the variable in subclass.

瞬态变量是否仅作为瞬态继承?如果子类反序列化会发生什么?反序列化子类后,瞬态变量是否会保持其行为并具有默认值.

Is transient variable inherited as transient only? What will happen if sub class is deserialized? Will the transient variable maintain its behavior and have the default value after deserialize subclass.

推荐答案

字段不能被继承,只能隐藏.如果您在超类中有一个 transient 字段,它的行为与序列化该类时的行为完全相同.

fields cannot be inherited, they can only be hidden. If you have a transient field in a super class it behaves exactly the same as it would if you serialized the class.

在反序列化子类后,瞬态变量是否会保持其行为并具有默认值.

Will the transient variable maintain its behavior and have the default value after deserialize subclass.

是的.你可以很容易地测试它,但它总是会这样做.

yes. You can test this fairly easily, but it will always do this.

这篇关于瞬态变量继承和子类被序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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