Is java object serialization compatible between 1.5 and 1.6

前端 未结 8 1904
灰色年华
灰色年华 2020-12-18 19:48

I am wondering whether it is safe to mix jdk 1.5 and 1.6 (Java 6) object serialization (biderctional communication). I searched for an explicit statement from sun concerning

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 20:14

    The serialization mechanism itself has not changed. For individual classes it will depend on the specific class. If a class has a serialVersionUID field, this is supposed to indicate serialization compatiblity.

    Something like:

    private static final long serialVersionUID = 8683452581122892189L;
    

    If it is unchanged, the serialized versions are compatible. For JDK classes this is guaranteed, but of course it is always possible to forget to update the serialVersionUID after making a breaking change.

    When JDK classes are not guaranteed to be compatible, this is usually mentioned in the Javadoc.

    Warning: Serialized objects of this class will not be compatible with future Swing releases

提交回复
热议问题