加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Java瞬态关键词语法糖?

发布时间:2020-12-15 08:27:47 所属栏目:Java 来源:网络整理
导读:为什么不通过使用注释而不是引入关键字来解决瞬态? 似乎transient关键字并没有真正为语言提供任何本机功能,并且似乎更具语法性,以防止意外序列化. 我错过了什么吗? 解决方法 Java transient keyword是从第一个java版本添加的,而Annotations后来在1.5版本中
为什么不通过使用注释而不是引入关键字来解决瞬态?

似乎transient关键字并没有真正为语言提供任何本机功能,并且似乎更具语法性,以防止意外序列化.

我错过了什么吗?

解决方法

Java transient keyword是从第一个java版本添加的,而Annotations后来在1.5版本中添加

实际上瞬态使用ad hoc annotation mechanism:

Java platform has always had various ad hoc annotation mechanisms. For example the transient modifier is an ad hoc annotation indicating that a field should be ignored by the serialization subsystem

请注意,Scala具有@transient且也是volatile:

@transient Marks a field to be non-persistent; this is equivalent to the transient modifier in Java.

@volatile Marks a field which can change its value outside the control of the program; this is equivalent to the volatile modifier in Java.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读