By default, the serialization mechanism encodes an object's class name, the names of its non-transient fields (including non-public fields), and thevalues of all of those fields.
上面这段话,是翻阅Serializable源码的时候看到的,transient 在Java里面是关键字,字面意思是瞬态的,可以参阅这篇博客http://www.blogjava.net/fhtdy2004/archive/2009/06/20/286112.html
被transient 修饰的成员变量fields 不会被序列化,包括非public的成员变量field
Changing the class name, field names or field types breaks serializationcompatibility and complicates interoperability between old and new versionsof the serializable class.
源码里有上面一段话,意思是告诉我们,不要修改类名,成员变量名,成员变量类型
Adding or removing fields also complicates serialization between versions of a class because it requires your code to cope with missing fields.
这段话也是说,增加和删除成员变量也不行
写到这里,我发现我写的内容,不如别人的博客写的好,各位同学若看到这里直接点到这个链接:http://www.blogjava.net/fhtdy2004/archive/2009/06/20/286112.html,里面写得很清晰
本文介绍了Java中Serializable接口的工作原理,强调了transient关键字的作用,指出被其修饰的字段不会被序列化。同时,讨论了修改类名、字段名或字段类型、添加或删除字段对序列化兼容性的影响,提醒开发者注意这些变化可能带来的问题。
1139

被折叠的 条评论
为什么被折叠?



