有一个图书馆https://github.com/thoughtbot/expandable-recycler-view
我想覆盖一个类
public class ExpandableGroup<T extends Parcelable> implements Parcelable {
private String title;
private List<T> items;
public ExpandableGroup(String title, List<T> items) {
this.title = title;
this.items = items;
}
public String getTitle() {
return title;
}
public List<T> getItems() {
return items;
}
public int getItemCount() {
return items == null ? 0 : items.size();
}
@Override
public String toString() {
return "ExpandableGroup{" +
"title='" + title + '\'' +
", items=" + items +
'}';
}
protected ExpandableGroup(Parcel in) {
title = in.readString();
byte hasItems = in.readByte();
int size = in.readInt();
if (hasItems == 0x01) {
items = new ArrayList<T>(size);
Class<?> type = (Class<?>) in.readSerializable();
in.readList(items, type.getClassLoader());
} else {
items = null;
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
if (items == null) {
dest.writeByte((byte) (0x00));
dest.writeInt(0);
} else {
dest.writeByte((byte) (0x01));
dest.writeInt(items.size());
final Class<?> objectsType = items.get(0).getClass();
dest.writeSerializable(objectsType);
dest.writeList(items);
}
}
@SuppressWarnings("unused")
public static final Creator<ExpandableGroup> CREATOR =
new Creator<ExpandableGroup>() {
@Override
public ExpandableGroup createFromParcel(Parcel in) {
return new ExpandableGroup(in);
}
@Override
public ExpandableGroup[] newArray(int size) {
return new ExpandableGroup[size];
}
};
}
这样您就可以使构造函数为空。和变量
String title, List<T> items
通过设置器添加。
我的问题是List<T>
.
我如何重写此类以使构造函数变为空?而且写入数据不方便
不能覆盖。怎样成为?
每个子类的构造函数都必须调用任何父构造函数,而不管这个构造函数的参数是什么(以及它是否有任何参数)。
您始终可以创建以下构造函数:
当然,除非它会在父构造函数中引发异常
如果您指定了特定类型的泛化,请在所有地方指定它