Java-transient Summary

Source: Internet
Author: User

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 class Transientdemo implements serializable{/** * */private static final long serialversionuid = 1L;    private transient String name;    private String password;    Public String GetName () {return name;    } public void SetName (String name) {this.name = name;    } public String GetPassword () {return password;    } public void SetPassword (String password) {this.password = password; }public static void Main (string[] args) throws FileNotFoundException, IOException, classnotfoundexception {//TODO auto-g    enerated method Stub String path= "D:" +file.separator+ "Object.txt";    File File=new file (path);    Transientdemo transientdemo=new Transientdemo ();    Transientdemo.setname ("name");    Transientdemo.setpassword ("password");    ObjectOutput output=new ObjectOutputStream (new FileOutputStream (file));    Output.writeobject (Transientdemo);    ObjectInput input=new ObjectInputStream (new FileInputStream (file)); Transientdemo demo= (TransiEntdemo) Input.readobject ();    System.out.println (Demo.getname () +demo.getpassword ());   }}

Result name output is null

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.