最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java中的transient關(guān)鍵字介紹

 更新時(shí)間:2015年03月26日 21:04:58   投稿:mdxy-dxy  
這篇文章主要介紹了Java中的transient關(guān)鍵字介紹,需要的朋友可以參考下

transient說(shuō)明一個(gè)屬性是臨時(shí)的,不會(huì)被序列化。
下面是一個(gè)Demo,name聲明為 transient,不被序列化

package com.zzs.tet;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

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;
	}

	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		// TODO Auto-generated method stub
		String path="D:"+File.separator+"object.txt";
		File file=new File(path);
		TransientDemo transientDemo=new TransientDemo();
		transientDemo.setName("姓名");
		transientDemo.setPassword("密碼");
		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());
	}

}

輸出結(jié)果:

null密碼

相關(guān)文章

最新評(píng)論

浙江省| 长汀县| 沙坪坝区| 江都市| 双柏县| 石楼县| 原阳县| 罗源县| 石首市| 乃东县| 涿鹿县| 玛曲县| 含山县| 天台县| 额敏县| 凉山| 邢台市| 孝义市| 辽宁省| 洛隆县| 平凉市| 盐津县| 崇州市| 东阳市| 施秉县| 马尔康县| 封丘县| 卓尼县| 贺州市| 宁蒗| 繁昌县| 石河子市| 常山县| 茶陵县| 崇左市| 西贡区| 隆安县| 克什克腾旗| 通化县| 海林市| 清丰县|