Are static variables serialized in Serialization process

后端 未结 9 1646
深忆病人
深忆病人 2020-12-04 12:30

I\'m stumbled upon understanding java serialization. I have read in many documents and books that static and transient variables cannot be serialized in Java. We declare a

9条回答
  •  悲哀的现实
    2020-12-04 13:03

    The serialVersionUID is also serialized in this case.

    Any static variable that is provided a value during class initialization is serialized.

    However in normal cases, where you would provide the value to a static variable at the main class / run-time would not be serialized.

    You can try to access the serialVersionUID by making it public and try to access it after deserialization.

    You can refer "http://javabeginnerstutorial.com/core-java-tutorial/transient-vs-static-variable-java/" for more information.

    Hope that helps. Cheers !!

提交回复
热议问题