开发者

What should I set serialVersionUID to be? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Does it开发者_StackOverflow matter what I choose for serialVersionUID when extending Serializable classes in Java?

Why generate long serialVersionUID instead of a simple 1L?

Are there any best practices or common naming schemes associated with setting the serialVersionUID?

I feel that most people start from 0 and increment from there. I personally started using the date (e.g. 09052011) because I felt that it was more descriptive.


There is no reason to prefer one manual value for a serialVersionUID over another. But you should never increment at all, you should adjust your readObject()/writeObject()/writeReplace()/readResolve()/serializableFields to preserve binary compatibility, not have a scheme in mind for when you break it.


You should usually have the serialVersionUID as a private static final field in your class; you can choose any value. If you don't specify one, a value is generated automatically (this approach can lead to problems as it is compiler (object structure) dependent. There is also a tool (serialVer) that ships with jdk that can be used to generate the id. The specs should be able to help on details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜