zzh

zzh

Can Jdk8 static variables be serialized?

First of all, static variables cannot be serialized.

Verification:
  • Entity class:
  • Serialization:
  • Deserialization:
  • Result:

image

  • Exception
    Deserialization code:

Result:

image

Reason analysis:

image
In other words, static variables are stored on the class object. Therefore, after sysRole sets the remark, it will be saved on the class object for subsequent use by SysRole objects.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.