一个类中有这样一个属性:private Set<Person> allPerson;
我一开始通过调用以下方法初始化该属性:(初始化语句:this.allPerson = (Set<Person>) fo.load();)public Object load() throws Exception {
Object obj = null;
ObjectInputStream input = null;
try {
input = new ObjectInputStream(new FileInputStream(this.file));
obj = input.readObject();
} catch (Exception e) {
throw e;
} finally {
try {
input.close();
} catch (Exception e) {
}
}
return obj;
}
}存在这样一个Person类的子类Student:通过doCreate方法传递:以下就是doCreate方法
public boolean doCreate(Person person)  { boolean flag = false;
this.allPerson.add(person);
try {
this.fo.save(this.allPerson);
} catch (Exception e) {
e.printStackTrace();
}
flag = true;
return flag;
}
然后问题就出现了:
System.out.println(person);输出的结果的确是student类的数据;但是allPerson的内容却永远是第一次运行输入的student对象的内容。。