开发者

Do built in java classes like hashmap ever change their serialVersionUID?

In a lot of my database entities, i store a serialized hashmap of various values. How likely is it that the built in java hashmap class will change serialVersionUID making it so i can no longer deserialize the hashmaps from the database?

Could 开发者_如何学运维this happen with a new java version release?


Could this happen with a new java version release?

If anything can happen, it will :), but seriously, if they do change the serialVersionUID, they are setting it up to be backward-incompatible - Something that has probably not happened in all these years.

  • JDK 6 binary incompatibilities: http://www.oracle.com/technetwork/java/javase/compatibility-137541.html#incompatibilities

  • JDK 5 binary incompatibilities: http://java.sun.com/j2se/1.5.0/compatibility.html#incompatibilities

  • JDK 1.4 binary incompatibilities: http://java.sun.com/javase/compatibility_j2se1.4.html#incompatibilities1.4

  • JDK 1.3 binary incompatibilities: http://java.sun.com/j2se/1.3/compatibility.html#incompatibilities1.3

  • JDK 1.2 binary incompatibilities: http://java.sun.com/products/archive/j2se/1.2.2_017/compatibility.html#incompatibilities1.2

All the serializable incompatibilities listed above are for the 'default' serialVersionUID


It could but it's highly unlikely. The Java Object Serialization Specification defines the exact algorithm for serialVersionUID generation (chapter 4 - http://download.oracle.com/javase/6/docs/platform/serialization/spec/class.html#4100) and also explains how type versioning works and what's considered a compatible type evolution (chapter 5 - http://download.oracle.com/javase/6/docs/platform/serialization/spec/version.html).

Back to your question. Should new Java version introduce a backward incompatible change in the HashMap definition it will come with a new serialization UID. Java 5 clearly showed how much backward compatibility means for Java - look at how generic types came with type erasure. I think you're perfectly safe. The worst thing that could happen is seeing the HashMap deprecated :) but I am sure it will still be compatible.


You're not 'perfectly safe'. It has happened, in the case of one of the RowSet implementations, and it isn't guaranteed not to happen for the entirety of Swing.

However it does remain highly unlikely for core classes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜