The
paper came to the end of shallow, I know this matter to preach-Lu
ask the canal that is clear so, for have fountainhead come--Zhu Xi
Transient has "temporary", "ephemeral" meanings, we have learned about Serializable,java serialization, and when we don't want to serialize it for certain variables, we can set this variable to transient,transient is the Java language keyword To indicate that a domain is not part of the serialization of the object.transient indicates that a property is temporary and will not be serialized.
Public classTransientdemoImplementsserializable{
/**
*
*/
private static final longSerialversionuid=1L;
Private TransientStringname;
PrivateStringPassword;
PublicStringGetName() {
returnname;
}
Public voidSetName(String name) {
This.name= Name;
}
PublicStringGetPassword() {
returnPassword;
}
Public voidSetPassword(String password) {
This.Password= password;
}
Public static voidMain(string[] args)throwsFileNotFoundException, IOException, classnotfoundexception {
// TODO auto-generated Method Stub
String path="D:"+file.Separator+"Object.txt";
File file=NewFile (PATH);
Transientdemo transientdemo=NewTransientdemo ();
Transientdemo.setname ("name");
Transientdemo.setpassword ("Password");
ObjectOutput output=NewObjectOutputStream (NewFileOutputStream (file));
Output.writeobject (Transientdemo);
ObjectInput input=NewObjectInputStream (NewFileInputStream (file));
Transientdemo demo= (Transientdemo) Input.readobject ();
System. out. println (Demo.getname () +demo.getpassword ());
}
}Result password output is null
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java-transient Summary