| Author |
serialVersionUID - does it matter what value you choose?
|
Sean Keane
Ranch Hand
Joined: Nov 03, 2010
Posts: 581
|
|
A quick question I was wondering if anyone had an answer to. When setting the serialVersionUID in a class is there any benefit to setting it to any particular value?
You can generate a value for the serialVersionUID. IDE's like Eclipse will do this for you. Where the generated value is based on the structure of the class just like Java will do at runtime if you don't set the serialVersionUID value.
But why bother doing this? Why not just assign 1 to the first version of the class? Then increment this value by 1 each time you want to change it?
|
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 12513
|
|
It doesn't matter at all. Typically, you would go 1, 2, 3, ..., but there are reasons why you might not. For example, when developing objects in a distributed environment where there's no central authority, you might use something similar to a UUID generator to hand out non-conflicting IDs to different participants.
The Eclipse IDE has support for both methods, but of course you don't need any IDE at all to manage serialVersionIDs. The main point of the serialVersionId is to ensure that when an application marshals an object that the serialized object actually conforms to the same architecture as was expected.
|
One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
|
 |
Sean Keane
Ranch Hand
Joined: Nov 03, 2010
Posts: 581
|
|
Tim Holloway wrote:but there are reasons why you might not. For example, when developing objects in a distributed environment where there's no central authority, you might use something similar to a UUID generator to hand out non-conflicting IDs to different participants.
Ah, that scenario makes the use of a generated value make sense! Thanks.
I'm working on the the OCMJD certification. So I think I will just stick with assigning the value 1 to each serialVersionID. Should be good enough.
|
 |
 |
|
|
subject: serialVersionUID - does it matter what value you choose?
|
|
|