I am implementing more classes which extend the Serializable interface. I understood it is good to mention a value for serialVersionUID.
private static final long serialVersionUID = 1024L;
So, given that i will use all those classes, should i give the same value for serialVersionUID for each class, or on the contrary, they have to be different?
Thank you.
They do not have to be different and also do not have to be the same. It is only used to ensure that some serialized object can be deserialized by that class. Basically, if you changed the code of a serialized class you should also change this value.
The serialVersionUID for one class has absolutely no relation to that of a different class. A corollary is that the serialVersionUID of one class has absolutely no effect on that of a different class.
Thus, you can use the same one for all classes if you wish, and update them all in bulk when any of your classes changes. You should understand the implications it would have to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With