看JDK HashMap的源码时,看到了一个平时用的比较少的java关键字:transient
网上搜索了下,当对象使用serialization机制作序列化存储时,对于不想存储的成员对象,可以使用该关键字声明。
默认的序列化机制写到流中的数据有:
1、对象所属的类
2、类的签名
3、所有的非transient和非static的属性
4、对其他对象的引用也会造成对这些对象的序列化
5、如果多个引用指向一个对象,那么会使用sharing reference机制 (看英文说明更明白)
The default serialization mechanism for an object writes the class of the object,
the class signature, and the values of all non-transient and non-static fields.
References to other objects (except in transient or static fields) cause those
objects to be written also. Multiple references to a single object are encoded
using a reference sharing mechanism so that graphs of objects can be restored
to the same shape as when the original was written.
关于java的Serialization序列化,可以参考这篇文章:http://zzy1943.iteye.com/blog/634418