1

Possible Duplicate:
Does it matter what I choose for serialVersionUID when extending Serializable classes in Java?
Why generate long serialVersionUID instead of a simple 1L?

Are there any best practices or common naming schemes associated with setting the serialVersionUID?

I feel that most people start from 0 and increment from there. I personally started using the date (e.g. 09052011) because I felt that it was more descriptive.

Community
  • 1
  • 1
tskuzzy
  • 35,812
  • 14
  • 73
  • 140
  • 3
    Have you googled "java serialversionuid best practice"? Anything look authoritative? Josh Bloch says it is fine to pick a number out of thin air, so if a date works for you it's probably fine. – Ray Toal Sep 06 '11 at 05:42
  • 1
    This might help you: [Does it matter what I choose for serialVersionUID when extending Serializable classes in java](http://stackoverflow.com/questions/605828/does-it-matter-what-i-choose-for-serialversionuid-when-extending-serializable-cla/605832#605832) – Harry Joy Sep 06 '11 at 05:45

2 Answers2

1

There is no reason to prefer one manual value for a serialVersionUID over another. But you should never increment at all, you should adjust your readObject()/writeObject()/writeReplace()/readResolve()/serializableFields to preserve binary compatibility, not have a scheme in mind for when you break it.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

You should usually have the serialVersionUID as a private static final field in your class; you can choose any value. If you don't specify one, a value is generated automatically (this approach can lead to problems as it is compiler (object structure) dependent. There is also a tool (serialVer) that ships with jdk that can be used to generate the id. The specs should be able to help on details.

Scorpion
  • 3,938
  • 24
  • 37
  • @EJP : please explain why "you can choose any value" doesn't qualify as an answer; when I have already stated the code convention to be followed while choosing the value. – Scorpion Sep 06 '11 at 09:53
  • OK but that's the only part that is an answer: the rest is really irrelevant. – user207421 Sep 06 '11 at 22:28
  • well that's your personal opinion which you are entitled to; I do not consider giving the context to an answer as irrelevant (also the question did really ask of best practices). – Scorpion Sep 07 '11 at 05:17