问题描述
如果继承了 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.
在反序列化子类后,瞬态变量是否会保持其行为并具有默认值.
是的.你可以很容易地测试它,但它总是会这样做.
yes. You can test this fairly easily, but it will always do this.
这篇关于瞬态变量继承和子类被序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!