MVP通用问题(Java)

龙刺客

我正在尝试编写MVP模式的接口和默认实现。但是,我收到我认为应该可行的错误消息。我收到的错误消息是:

required: CAP#1
  found: MVPPresenter<M,V>
  reason: actual argument MVPPresenter<M,V> cannot be converted to CAP#1 by method invocation conversion
  where V,M,P are type-variables:
    V extends IMVPView< ? extends IMVPPresenter< ?,V>> declared in class MVPPresenter
    M extends Object declared in class MVPPresenter
    P extends IMVPPresenter< ?,? extends IMVPView< P>> declared in interface IMVPView
  where CAP#1 is a fresh type-variable:
    CAP#1 extends IMVPPresenter< ?,V> from capture of ? extends IMVPPresenter< ?,V>

这对我来说没有意义,因为MVPPresenter应该是CAP#1。有人可以解释为什么我不能这样做或提供解决问题的方法吗?

/**
 * Interface for the presenter in MVP
 *
 * @param <M> Model type
 * @param <V> View type
 */
public interface IMVPPresenter<M, V extends IMVPView<? extends IMVPPresenter<?, V>>> {
    ...
}

/**
 * Interface for the view in MVP
 *
 * @param <P> Presenter type
 */
public interface IMVPView<P extends IMVPPresenter<?, ? extends IMVPView<P>>> {
    ...
    public void setPresenter(P presenter);
}

/**
 * Default implementation of the presenter interface
 *
 * @param <M> Model Type
 * @param <V> View Type
 */
public class MVPPresenter<M, V extends IMVPView<? extends IMVPPresenter<?, V>>>
    implements IMVPPresenter<M, V> {
    ...
    protected void setView(V view) {
        ...
        view.setPresenter(this); // Error on this line
    }
}
霍尔格

具体的课程必须……具体得多。

public class MVPPresenter<M, V extends IMVPView<MVPPresenter<M,V>>>
  implements IMVPPresenter<M, V> {

  protected void setView(V view) {
    view.setPresenter(this); // No more error on this line
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章