我有以下类/接口层次结构:
interface BaseView {
//some base view methods
}
interface BasePresenter<V extends BaseView> {
void bindView(V view);
}
到目前为止这很简单,但我正在建立它:
interface GenericView extends BaseView {
//some generic view methods
}
interface GenericPresenter<V extends GenericView> extends BasePresenter<V> {
//some generic presenter methods
}
现在让我们来看看GenericView的实现:
abstract class GenericViewImpl<V extends GenericView, P extends GenericPresenter<V>> extends BaseViewImpl implements GenericView {
protected P presenter;
void onLifecycleCreationEventCalled() {
presenter.bindView((V) this); //on this line I have to do an unchecked cast to V in order to make it work
}
}
这些GenericView
和GenericPresenter
内部有多个方法+它们有多个指定的实现。
我的问题是:如何更改类层次结构以避免未经检查的强制转换?