package Nov2016; import java.io.Serializable; // V1.0版 public class Ques1114 implements Serializable{ private static final long serialVersionUID = 1L; public final int num; public Ques1114(){ num = 123; } }
// 序列化到磁盤 public class TestSerialize{ public static void main(String[] args) { SerializeUtils.writeObject(new Ques1114()); } }
// V2.0版 修改num值(serialVersionUID保持不變) public class Ques1114 implements Serializable{ private static final long serialVersionUID = 1L; public final int num; public Ques1114(){ num = 321; } }
// 反序列化 public class TestDeserialize{ public static void main(String[] args) { Ques1114 ques1114 = (Ques1114)SerializeUtils.readObject(); System.out.println(ques1114.num); // 輸出值 } }
今日問題:
通過20161111問題知道反序列化時final屬性會重新計算值,那這裡請問“輸出”處輸出結果是什麼?(點擊以下“【Java每日一題】20161114”查看20161111問題解析)
題目原發布於公眾號、簡書:【Java每日一題】20161114,【Java每日一題】20161114