简体   繁体   English

瞬态变量被继承,子类被序列化

[英]Transient variable inherited and subclass is serialized

If transient variable from a Serializable class is inherited and if i change the value of the variable in subclass. 如果从Serializable类继承了瞬态变量,并且如果我更改了子类中变量的值,则将其赋值。

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. 反序列化子类后,瞬态变量将保持其行为并具有默认值吗?

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. 如果您在超类中具有一个transient字段,则其行为与序列化该类时的行为完全相同。

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. 您可以相当轻松地测试它,但是它总是会这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM