反序列化时,并没有强制转换,为什么还能正常打印结果
package com.IOUtil.io;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class ObjectSeriaDemo01 {
public static void main(String[] args) throws IOException, ClassNotFoundException {
/*
//对象的序列化
String file = "demo\\obj.dat";
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
Student stu = new Student("012", "王栋祥", 22);
oos.writeObject(stu);
*/
//对象的反序列化
String file = "demo\\obj.dat";
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
//ois.readObject();
System.out.println(ois.readObject());
}
}