我正在尝试在android中实现基本抽象类。
我的基本抽象类是BaseItemPresenter类。课程如下:
public abstract class BaseItemPresenter<T extends MvpView> extends BasePresenter<T> {
public abstract void loadFromDevice();
public abstract void loadFromFile();
public abstract void backup(List<? extends BaseBackupItem> list);
public abstract void delete(List<? extends BaseBackupItem> list);
public abstract void restore(List<? extends BaseBackupItem> list);
public abstract void sort(int sortType, boolean isAscending);
public abstract void sort(List<? extends BaseBackupItem> list, int sortType, boolean isAscending);
public abstract void filter(List<? extends BaseBackupItem> list, Class<? extends MvpView> filterOptions);
}
我正在用ItemPresenter1类实现这个类。代码如下:
public class ItemPresenter1 extends BaseItemPresenter<MvpView> {
@Override
public void loadFromDevice() {
}
@Override
public void loadFromFile() {
}
@Override
public void backup(List<Item1> list) {
}
@Override
public void delete(List<Item1> list) {
}
@Override
public void restore(List<Item1> list) {
}
@Override
public void sort(int sortType, boolean isAscending) {
}
@Override
public void sort(List<Item1> list, int sortType, boolean isAscending) {
}
@Override
public void filter(List<Item1> list, Class<View1> filterOptions) {
}
}
Item1类正在扩展BaseBackupItem类。 View1类正在扩展MvpView类。
public class Item1 extends BaseBackupItem {
}
public class View1 extends MvpView {
}
所以,我应该如何解决这个问题:
来自:
public abstract void backup(List<? extends BaseBackupItem>);
到:
@Override
public void backup(List<Item1>);
错误:
Method does not override method from its superclass.
答案 0 :(得分:1)
您需要在BaseItemPresenter
的班级定义中添加新类型参数,以便将List
的预期类型指定为下一个:
public abstract class BaseItemPresenter<T extends MvpView, I extends BaseBackupItem>
extends BasePresenter<T> {
...
public abstract void backup(List<I> list);
public abstract void delete(List<I> list);
public abstract void restore(List<I> list);
...
}
然后您的班级ItemPresenter1
将被声明为下一个:
public class ItemPresenter1 extends BaseItemPresenter<MvpView, Item1 > {
...
@Override
public void backup(List<Item1> list) {