I thought this would throw an error saying minor version number; But it didn't. And is working correctly. Can anyone point out, why does this work?
I created a hashMap in application running on java 1.7, serialized it and sent it to an application using jdk 1.6. The receiver application was able to get the contents without any error.
This is where the serialVersionUID
attribute comes into play.
In the HashMap
class both the Java version 6.0 and 7.0 the serialVersionUID
is the following:
private static final long serialVersionUID = 362498820763181265L;
This means no changes were made to the class which would change how the object is serialized therefore you get no error if different versions of Java was used to serialize/deserialize the object, both are able to serialize/deserialize the object properly.
Moreover, even Java 8.0 has the same serial version UID for HashMap and also Java 5.0 (and even 1.4), which means you can read/write HashMap
s with Java 1.4-5-6-7-8 without any problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With