Can SerialVersionUid be any number or should it be generated by the compiler?

If I write serialversionUid for my class, as 1234 say, and I know that no other class in my program uses this, is that fine or do I always need to use the uid generated by the compiler?

+4
source share
2 answers

serialVersionUID can be long, which provides a unique signature for your object for serialization and deserialization. I don’t think it should even be unique. This means that the serializer knows that it is the same Foo.class, even after you change the structure of the class. Usually I use -1L for value.

+2
source

It can be any number, and he only needs to submit a version of this class. This does not have to be unique.

+2
source

Source: https://habr.com/ru/post/1306642/


All Articles