How serialversionuid is calculated

前端 未结 2 1033
猫巷女王i
猫巷女王i 2020-12-31 17:47

When I create Java Class in Eclipse which implements Serializable interface, I get a warning

The serializable class ABCD does not declar

2条回答
  •  被撕碎了的回忆
    2020-12-31 18:02

    Automatically generated serialVersionIds are a hash based on the method signatures, parameters and such like in the class. It's done this way so that the serialVersionId will change whenever you change your class, indicating to the serialization mechanism that there data/class are no longer compatible. That's the default.

    When you define your own, just start with 1, and increment when the class is no longer compatible with previously serialized data.

提交回复
热议问题