鉴于这一组interfaces
:
interface BaseView {
}
interface UserView extends BaseView {
void showMe(User user);
}
interface Presenter {
void attachView(BaseView view);
}
interface UserPresenter extends Presenter {
void logout();
}
我创建了一个abstract class
,它将用作基础clase基础。我试图在这个类中用泛型定义将由子类实现的interface
的类型。像这样:
public abstract class Screen<P extends Presenter, V extends BaseView> implements V {
private final P presenter;
public Screen(P presenter) {
this.presenter = presenter;
this.presenter.attachView(this);
}
}
这样,子类可以定义如下:
public class UserScreen extends Screen<UserPresenter, UserView> {
@Override showMe(User user) {
}
private void clickButtonLogout() {
presenter.logout();
}
}
嗯,这就是我想要实现的目标。但这行不编译:
public abstract class Screen<P extends Presenter, V extends BaseView> implements V
错误:此处需要接口
通过&#34; here&#34;,编译器意味着通用类型V。
那么,有没有办法指定子类将使用泛型实现的接口类型?