静态字段值未序列化。输出是打印静态字段的新值,仅仅是因为您已将其修改为999999,但从未在反序列化之前将其值重置为旧值。由于该字段是静态的,因此新值会反映在的
任何 实例中
ChildClass。
若要正确断言该字段未序列化,请在对对象进行反序列化之前将其值重置为10001,您会注意到其值不是999999。
...ChildClass.setStaticState(10001);FileInputStream fi = null;ObjectInputStream ois = null;ChildClass streamed;...// when de-serializing, the below will print "state101 static state 10001"System.out.println(streamed.toString());



