关键字“瞬态”是什么?用Java表示? [英] What does the keyword "transient" mean in Java?

查看:257
本文介绍了关键字“瞬态”是什么?用Java表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某个地方看到了



transient private TrackDAO trackDAO;


推荐答案

Google是你的朋友 - 第一次点击 - 你也可以先看看序列化是。

Google is your friend - first hit - also you might first have a look at what serialization is.


它标记成员变量不是
序列化当它持久化到
字节流时。当一个对象是通过网络传输的
时,
对象需要序列化。
序列化将对象
状态转换为串行字节。这些字节是通过网络发送的
,并且从这些字节重新创建对象
。由java transient
关键字标记的成员
变量不会被转移,它们是故意丢失

It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.

来自那里的示例,略有修改(感谢@pgras):

Example from there, slightly modified (thanks @pgras):

public class Foo implements Serializable
 {
   private String saveMe;
   private transient String dontSaveMe;
   private transient String password;
   //...
 }

这篇关于关键字“瞬态”是什么?用Java表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆