What means 1L serialVersionUID? When could I use this default value 1L?

前端 未结 8 1984
生来不讨喜
生来不讨喜 2021-02-05 07:02

There are 3 ways to define the serialVersionUID :

1. private static final long serialVersionUID = 1L; (Default)
2. private static final long serialVersionUID = -         


        
8条回答
  •  [愿得一人]
    2021-02-05 07:42

    The value is used while serializing an object and de-serializing the object back into JVM.

    Further, If your class changes and you don't want to support backward compatibility (i.e. able to de-serialize the object back which was serialized using your last version of class) you can change the version number to any other value.

    However, to support the backward compatibility you need to keep the same version number as previously set value of serialVersionUID.

    The best practice is to change the serialVersionUID, every time you have some incompatible changes to the class.

提交回复
热议问题