Friday, August 31, 2007

serialVersionUID from java 5

I started using eclipse with java 5. I got this a compilation warning in one of the realizable class, which said something to the effect that it needs a 'serialVersionUID' field.


http://www.doc.ic.ac.uk/csg/java/1.5.0docs/api/java/io/Serializable.html


The 'serialVersionUID' field helps with making sure that the version of the class that has been serialized, is the same as the version of the class that is de-serialized and if it is not the a invalidClassException is thrown.

The field looks like 'private static final long serialVersionUID = 42L'.

Since it needs to be a static field, i guess each class and it's subclasses will need have one field per class declared if there is a heirarchy of classes that need to be serialized.

0 Comments:

Post a Comment

<< Home