简体   繁体   中英

Order of class initialization during java deserialization

During deserialization, are subclasses guaranteed to be initialized before any class instance objects are restored from the input stream? Specifically, I have a subclass with static fields that I'd like to access in the superclass readObject() method. Can I count on the subclass static fields being valid?

I am not an expert on BNF, but the protocol spec for serialization

classDescInfo:
  classDescFlags fields classAnnotation superClassDesc 

shows that superclass information comes after class information. So it looks like you can rely on your subclass static fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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