Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of extending Java serializable class? [duplicate]

Possible Duplicate:
Why does a class implements Serializable interface?

I'm using a tutorial found here: http://www.objectdb.com/tutorial/jpa/eclipse/ee/entity

I'm wondering why this class extends Serializable? I've read the description of this class and I don't understand the importance of serialVersionUID and why it's necessary for my model.

like image 385
Webnet Avatar asked Dec 10 '11 07:12

Webnet


1 Answers

It doesn't extend a class - it implements the Serializable interface, which is basically just a marker interface to say "I'm fine to be serialized".

The idea is to be able to transparently serialize instances of the class - potentially for caching or other purposes, I'm not sure in this case. The serialVersionUID field is just part of the versioning that Java binary serialization uses.

like image 160
Jon Skeet Avatar answered Sep 28 '22 08:09

Jon Skeet