【发布时间】:2017-11-02 01:28:15
【问题描述】:
我已经定义了一个这样的类
abstract class MvpViewHolder<P>(itemView: View) : RecyclerView.ViewHolder(itemView) where P : BasePresenter<out Any?, out Any?> {
protected var presenter: P? = null
fun bindPresenter(presenter: P): Unit {
this.presenter = presenter
presenter.bindView(itemView)
}
}
presenter.bindView(itemView) 给了我一个错误声明 Type mismatch, required: Nothing, found: View!。我在presenter 类中定义了bindView,就像这样
abstract class BasePresenter<M, V> {
var view: WeakReference<V>? = null
var model: M? = null
fun bindView(view: V) {
this.view = WeakReference(view)
}
}
它的值是view: V。
我尝试使用星形语法BasePresenter<*,*> 定义我的BasePresenter<out Any?, out Any?> 扩展,但我得到了同样的错误。我也尝试过仅使用 BasePresenter<Any?, Any?> 来解决直接问题,但是任何扩展 P: BasePresenter<Any?, Any?> 的东西都会出错,说它期待 P,但得到了 BasePresenter<Any?, Any?>
这是在我的代码中发生的示例
abstract class MvpRecyclerListAdapter<M, P : BasePresenter<Any?, Any?>, VH : MvpViewHolder<P>> : MvpRecyclerAdapter<M, P, VH>() {...}
在这一行上,我会在扩展MvpRecyclerAdapter<M, P, VH> 部分得到上述错误
我似乎无法解决这个问题。我该如何解决?
【问题讨论】:
标签: android generics kotlin kotlin-android-extensions kotlin-extension