首页 > 其他 > 详细

序列化与transient

时间:2021-05-22 23:21:37      阅读:15      评论:0      收藏:0      [点我收藏+]

java keyword: transient
usage: skip serialization for transient-field

import java.io.*;
class Test implements Serializable
{
    int i = 10;
  
    transient int k = 30;
  
    transient static int l = 40;

    public static void main(String[] args) throws Exception
    {
        Test input = new Test();
  
	// write the Test-class obj to the file
        FileOutputStream fos = new FileOutputStream("abc.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(input);
	// read to Test-class obj from the file
        FileInputStream fis = new FileInputStream("abc.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Test output = (Test)ois.readObject();
    }
}
// [OUT]:Test-obj output is { i = 10;k = 0;l = 40}

序列化与transient

原文:https://www.cnblogs.com/1river/p/14799763.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!