int company_id; String company_addr; public Serial1(int company_id, String company_addr) { this.company_id = company_id; this.company_addr = company_addr; }
public String toString() { return "DATA: "+company_id+" "+ company_addr; } public void todo(){}//无关紧要的方法 } 首先将老版本序列化,然后用新版本读出,发生错误:
java.io.InvalidClassException: Serial.Serial1; local class incompatible: stream classdesc serialVersionUID = 762508508425139227, local class serialVersionUID = 1187169935661445676 接下来我们加入显式的声名UID:
private static final long serialVersionUID=762508508425139227l; 再次运行,顺利地产生新对象