views:

58

answers:

2

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?

+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
Here is another reason to set your own serialVersionUID - http://www.javafaq.nu/java-article994.html
Chuk Lee
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
EJP you are correct. It's a unique object signature for serialization. Thx
Chuk Lee
+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