If I write a serialversionUid for my class as say 1234, and I know that no other class in my program uses that, is that fine or do i always have to use a uid generated by the compiler?
views:
58answers:
2
+2
A:
serialVersionUID can be any long that provides a unique signature to your object for serialization and deserialization. I don't think it even have to be unique. This is so that the serializer knows that that is the same Foo.class even after you have change the structure of the class. I typically use a -1L for the value.
Chuk Lee
2010-04-12 02:31:20
Here is another reason to set your own serialVersionUID - http://www.javafaq.nu/java-article994.html
Chuk Lee
2010-04-12 02:33:01
That's not correct. At best it's poorly stated. It doesn't have to be unique, as your own usage of -1L shows, and its function is not to 'uniquely identify your object'. Its function is to define its serialization signature, as the name implies.
EJP
2010-04-12 08:55:46
EJP you are correct. It's a unique object signature for serialization. Thx
Chuk Lee
2010-04-12 08:59:34
+2
A:
It can be any number, at it only has to represent the version of that class. It does not have to be unique at all.
Yishai
2010-04-12 02:32:24