序列化和反序列化,
package demo06; import java.io.Serializable; public class Pserson implements Serializable { private static final long serialVersionUID = 1L; private String name; private int age; @Override public String toString() { return "Pserson{" + "name='" + name + '\'' + ", age=" + age + '}'; } public Pserson(String name, int age) { this.name = name; this.age = age; } public Pserson() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
添加这个
serialVersionUID = 1L;就可以防治
每次类的改动造成类的Serializable ID的改变,反序列化的时候报错
serialVersionUID = 1L;就是这个类一直不变的ID