Java-transient Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.