How to serialize static data members of a Java class?

后端 未结 9 1908
孤城傲影
孤城傲影 2020-11-27 17:30

When we serialize objects, static members are not serialized, but if we need to do so, is there any way out?

9条回答
  •  星月不相逢
    2020-11-27 17:55

    To have compact implementation, implement readObject & writeObject in your class call defaultReadObject & defaultWriteObject methods within those methods which handles normal serialization and then proceed with serializing & de-serializing whatever additional fields you need.

    Regards, GK

提交回复
热议问题