| Author |
The serializable class does not declare a static final serialVersionUID
|
Kowshik Nandagudi
Ranch Hand
Joined: Dec 09, 2010
Posts: 57
|
|
1 ) What does The serializable class PositionCollector does not declare a static final serialVersionUID field of type long mean ?
2) What actually happens behind the scene if i implement Serializable class?
3) What is the role of this id?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
Kowshik Nandagudi wrote:1 ) What does The serializable class PositionCollector does not declare a static final serialVersionUID field of type long mean ?
It means you are using Eclipse; other IDEs tend to keep quiet about it
. . .
3) What is the role of this id?
It ensures that you are deserialising from a particular version of a class to the same version. Imagine you have a Car classNow imagine you add a new field to the class, in newer versions of the application.If you serialize an object of the first Car class, and deserialize it into the newer Car class, where will the CD_Player object be? What the SUID does here, is to tell the JVM that despite the similar name, they are different classes. I think in that case, an Exception willl be thrown, but I am not certain.
There are at least three things you can do with SUIDs1: Leave it out. That tells the JVM that you are not worrying whether different versions of the class are the same.2: Use the same SUID throughout (unzip the String class and look at its code). That tells the JVM to treat all versions of the class as if they were the same version.3: Give different versions different SUIDs. That tells the JVM to treat them as different versions, not mutually serializable with one another.There is a serialver tool which adds a SUID to a class.
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Main purpose of this is to check for the compatibility between the class file available for the JVM and the serialized object stream. Read all about it here
Edit: Ah... I had to go out a bit since started to reply to this. Campbell has already replied
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
 |
|
|
subject: The serializable class does not declare a static final serialVersionUID
|
|
|