国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Java > 正文

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

2019-11-26 15:14:47
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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密碼

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 丰县| 贡山| 辉县市| 扬中市| 厦门市| 林甸县| 西安市| 龙口市| 石柱| 锡林浩特市| 读书| 冷水江市| 苏州市| 马山县| 正镶白旗| 铜山县| 五指山市| 永定县| 邻水| 玛曲县| 宜阳县| 金阳县| 井研县| 牡丹江市| 安庆市| 林芝县| 简阳市| 南涧| 江永县| 和田县| 望奎县| 阿尔山市| 舒兰市| 金坛市| 当雄县| 漯河市| 闽清县| 剑川县| 来凤县| 江山市| 大丰市|