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

前端 未结 8 1986
生来不讨喜
生来不讨喜 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:30

    What is the meaning? Is that useful?

    Yes. The point of serialVersionUID is to give the programmer control over which versions of a class are considered incompatible in regard to serialization. As long as the serialVersionUID stays the same, the serialization mechanism will make a best effort to translate serialized instances, which may not be what you want. If you make a semantic change that renders older versions incompatible, you can change the serialVersionUID to make deserializing older instances fail.

    If all classes have the same serialVersionUID 1L, is there no problem?

    No - the serialVersionUID is per class.

提交回复
热议问题