Search code examples
javaserializableserialversionuid

SerialVersion UID Java - How SerialVersionUID work?


Hello I've one question about SerialVersionUID in Java. If I generate a SerialVersionUID for class A, 2 instances of A have the same SerialVersion about class and another unique Serial for the object, different about object1 and object2? Or how? I don't understand, please reply me. Thanks.


Solution

  • SerialVersionUID is way to identify a class's version. So all objects of the same class will have the same SerialVersionUID. However if you make change to the class, it is recommended to change the SerialVersionUID. And then in case of incompatibility, the serialization of the object would fail.

    See: What is a serialVersionUID and why should I use it?