transient是什么意思的简单介绍
java 方法中含有 transient 是什么意思?
transient”——“瞬态”,先不说这个翻译是否恰当,这个变量关键字一直不曾使用,简单的说就是被瞬态定义的变量不可序列号。或者这么给他换个名字——“不可序列化状态”。
打个比方,如果一个用户有一些敏感信息(譬如密码,****等),为了安全起见,不希望在网络操作(主要涉及到序列化操作,本地序列化缓存也适用)中被传输。这些信息对应的变量就可以被定义为transient类型。换句话说,这个字段的生命周期仅存于调用者的内存中。
如定义类:

public class People implements Serializable {
private static final long serialVersionUID = 8294180014912103005L;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private transient String password;
}
密码字段为transient,这时候如果对该对象进行序列化,这个密码字段是不会被保存的。
以下例子展示了这个行为:
public static void main(String[] args) throws Exception {
People p = new People();
p.setUsername("snowolf");
p.setPassword("123456");
System.err.println("------操作前------");
System.err.println("username: " + p.getUsername());
System.err.println("password: " + p.getPassword());
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
"people.txt"));
oos.writeObject(p);
oos.flush();
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"people.txt"));
p = (People) ois.readObject();
ois.close();
System.err.println("------操作后------");
System.err.println("username: " + p.getUsername());
System.err.println("password: " + p.getPassword());
}
执行结果是:
------操作前------
username: snowolf
password: 123456
------操作后------
username: snowolf
password: null
transient和transitory的区别
transitory 只为形容词。形容短暂的一瞬的,另有无常的意思。
transient 可为形容词和名词 形容词多形容在短时间内的。名词为暂住客。
例句:
1Their turmoil may be transient.
他们的混乱也许是短暂的。
2Many of the drags on first-quarter output are transitory.
第一季度生产的很多减缓是暂时的。
注解transient是什么意思
java语言的关键字,变量修饰符,如果用transient声明一个实例变量,当对象存储时,它的值不需要维持。 Java的serialization提供了一种持久化对象实例的机制。当持久化对象时,可能有一个特殊的对象数据成员,我们不想用serialization机制来保存它。为了在一个特定对象的一个域上关闭serialization,可以在这个域前加上关键字transient。当一个对象被串行化的时候,transient型变量的值不包括在串行化的表示中,然而非transient型的变量是被包括进去的。
java中的关键字transient是什么意思
使用transient修饰符来标识一个成员变量在序列化子系统中应被忽略。
transient:
使用对象:字段
介绍:字段不是对象持久状态的一部分,不应该把字段和对象一起串起。
在JPA实体中,所有未使用Transient注释(由JPA定义)进行注释的非瞬态字段都是持久化字段。“持久化”意味着字段被映射到数据库中的列。请注意,Patient类中的一些持久化字段没有注释。这是由于JPA定义的默认值(如默认的列名称)对于这些字段来说是正确的。如果字段名称与其映射的数据库列名称不同,则必须使用Column注释来为数据库列指定一个不同的列名称。
transient是什么意思
transient
英 ['trænzɪənt] 美 ['trænzɪrnt]
adj. 短暂的;路过的
n. 瞬变现象;过往旅客;候鸟
It is transient in the sense that it exists only during the running of the process.
它仅在流程运行的过程中存在,从这个角度来讲,它是瞬态 的。