What is Serial Version ID in Java?

Possible Duplicates:
Why should I bother about serialVersionUID?
what is a serial version id?

When i created a new class extending java.util.logging.Level in Eclipse, It asked me to add a default or generated serial version ID. I just added blindly without knowing what it is and why I have to add it.

Can anybody tell me what is it and why it its required.


The Serial Version ID is used when serializing and deserializing an object. Java recognizes if the bytes you want to deserialize match the local class version. If not it will throw an exception.

This is important when doing RMI or persisting object structures.

There's a very good description about serializing in the javadoc of Serializable.


It is the unique identifier for the class, used for serialization.

It is wise to declare it if you're serializing asap because if you don't declare one then when changing the class it will get a different one generated automatically and the serialization will stop working.

A good reference is here: http://c2.com/ppr/wiki/JavaIdioms/AlwaysDeclareSerialVersionUid.html

链接地址: http://www.djcxy.com/p/23828.html

上一篇: 什么是java中的serialVersionUID,通常在异常类中?

下一篇: 什么是Java中的串行版本ID?