我正在调查auto-value
及其扩展,即auto-value-parcel
在auto-value-parcel-adapter
我的 Android 应用程序中。
我有这些模型类:-
@AutoValue
public abstract class Xenarchaeota implements Parcelable {
@ParcelAdapter(AmoebaTypeAdapter.class)
public abstract Set<Amoeba> amoebas();
public static Builder builder() {
return new AutoValue_Xenarchaeota.Builder();
}
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setAmoebas(Set<Amoeba> value);
public abstract Xenarchaeota build();
}
}
和
@AutoValue
public abstract class Amoeba implements Parcelable {
public abstract String surname();
public static Builder builder() {
return new AutoValue_Amoeba.Builder();
}
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder surname(final String value);
public abstract Amoeba build();
}
}
我的类型适配器是我出现问题的地方
class AmoebaTypeAdapter implements TypeAdapter<Set<Amoeba>> {
@Override
public Set<Amoeba> fromParcel(Parcel in) {
final ArrayList<Amoeba> arrayList = new ArrayList<>();
in.readTypedList(arrayList, Amoeba.CREATOR); // How to access the CREATOR?
return new TreeSet<>(arrayList);
}
@Override
public void toParcel(Set<Amoeba> value, Parcel dest) {
final ArrayList<Amoeba> arrayList = new ArrayList<>(value);
dest.writeTypedList(arrayList);
}
}
我需要传递给 readTypedArray 的 CREATOR 在 AutoValue_Amoeba 中声明。
我的错误在哪里?误解auto-value-parcel
?