java transient关键字

看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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值