public class Foo {
private String id = null;
public String getId() { return id; }
public Foo setId(String id) { this.id = id; return this; }
}
不幸的是,XMLEncoder不在此处输出id属性:
try (XMLEncoder out = new XMLEncoder(new FileOutputStream(new File("out.xml"))) {
out.writeObject(new Foo());
}
除非我将setter返回类型更改为void。