6

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.

Community
  • 1
  • 1
Ben
  • 60,438
  • 111
  • 314
  • 488
  • possible duplicates: 1) http://stackoverflow.com/questions/7298782/why-does-a-class-implements-serializable-interface 2)http://stackoverflow.com/questions/970891/who-actually-implements-serializable-methods 3) http://stackoverflow.com/questions/441196/why-java-needs-serializable-interface – jFrenetic Dec 10 '11 at 08:39
  • As for the question regarding why **this particular** class needs to implement `Serializable`, see the most voted answer [here](http://stackoverflow.com/questions/2020904/when-and-why-jpa-entities-should-implement-serializable-interface) – jFrenetic Dec 10 '11 at 08:45

1 Answers1

11

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194