views:

659

answers:

2

I'm extending a class (ArrayBlockingQueue) that implements the Serializable interface. Sun's documentation (and my IDE) advises me that I should set this value in order to prevent mischief:

However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization.

Now, I couldn't care less about what value to put in there. Does it matter?

+11  A: 

No - so long as you change it at the right time (i.e. when you make a change which affects serialization, e.g. removing a field) it shouldn't matter what value you use.

For simplicity I'd suggest starting with 0 and increasing it by 1 each time you need to.

The serialization spec has more details.

Jon Skeet
+5  A: 

The only thing that matters for the serialVersionUID is that binary-compatible serialized versions of the class have the same serialVersionUID; that is if you've not made any breaking changes to the serialized form of the class it'll be fine.

Of course, a better option is to use the advanced options that serialization makes available to you so that there are never any breaking changes. I'd suggest reading about readResolve() et al. Effective Java covers some of the thornier issues in this area in detail.

GaryF