关于JDK中的transient关键字

  • 前段时间参加面试被问到了 HashMap 的原理,但是对 HashMap 的了解都是通过博客,一面建议我还是多看看源码,博客的知识毕竟有一些过时了,所以今天就来研究研究源码,然后发现HashMap的变量里有一个transient关键字,从来没见过,于是去百度了一下,现在做个总结好了~
Java's serialization provides an elegant, and easy to use mechanism for making an object's state persistent.

While controlling object serialization, we might have a particular object data member that we do not want the serialization

mechanism to save.To turn off serialization on a certain field of an object, we tag that field of the class of our object with

the Java's "transient" keyword. This, to low-level parts of the Java virtual machine, is an indication that the transient variable

is not part of the persistent state of an object.
  • 其实这个关键字说白了就是当对象需要序列化输出的时候,用户不希望某个变量被序列化输出,就用此关键字标记一下,然后当对象序列化输出时,被此关键字标记的变量是不会保存在硬盘中的,所以读取的时候该变量为空。
  • 参考文献
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值