我有这堂课:
public class Foo implements Parcelable {
private int id;
private MyFoo myFoo
private ForeignCollection<MyFoo2> myFoo2s;
public void writeToParcel(Parcel out, int flags) {
out.writeInt(id);
out.writeParcel(myFoo, flags);
out.write //How can I write the ForeignCollection?
}
public Foo(Parcel in) {
id = in.readInt();
myFoo = in.readParcelable(getClass().getClassLoader())
myFoo2s = // How can I read the ForeignCollection?
}
public static final Parcelable.Creator<Foo> CREATOR = new Parcelable.Creator<Foo>() {
public Foo createFromParcel(Parcel in) {
return new Foo(in);
}
public Foo[] newArray(int size) {
return new Foo[size];
}
};
}
MyFoo 和 MyFoo2 类也实现 Parcelable,但 ForeignCollection 没有这样做。ForeignCollection是一个实现接口的类:Collection、CloseableIterable 和 Iterable。
我不能使用out.writeList
,因为 ForeignCollection 没有实现 List 接口。