Android Kotlin函数不需要任何东西,但定义为不同的类型

Android Kotlin函数不需要任何东西,但定义为不同的类型,android,generics,kotlin,kotlin-android-extensions,kotlin-extension,Android,Generics,Kotlin,Kotlin Android Extensions,Kotlin Extension,我定义了这样一个类 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.p

我定义了这样一个类

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)
    }
}
它的值为
视图:V

我尝试使用star syntaxt
BasePresenter
定义我的扩展名
BasePresenter
,但我得到了相同的错误。我也尝试过简单地使用
BasePresenter
来解决直接问题,但是任何扩展
P:BasePresenter
的操作都会出现一个错误,表示它需要P,但得到了
BasePresenter

下面是一个在我的代码中发生的示例

abstract class MvpRecyclerListAdapter<M, P : BasePresenter<Any?, Any?>, VH : MvpViewHolder<P>> : MvpRecyclerAdapter<M, P, VH>() {...}
抽象类MvpRecyclerListAdapter:MvpRecyclerAdapter(){…}
在这一行中,我将在extends
MvpRecyclerAdapter


我似乎无法回避这件事。如何修复它?

您已经在
BasePresenter
为泛型参数V声明了out,因此
presenter.bindView
不能接受输入参数

解决方案:将声明更改为
BasePresenter


检查更多信息。

它仍然会在这一行给我错误
抽象类MvpRecyclerListAdapter:MvpRecyclerAdapter(){…}
声明,特别针对
P
,它
期望
P`但找到BasePresenter@Rafa在泛型中
P
的用法不应该到处都是
P:BasePresenter
。。我是说仿制药很好,但你和他们一起进城了……你说得对。是的,我正在使用MVP启动一个应用程序,我正在尝试将此代码转换为Kotlin。事实证明,将通用签名转换为Kotlin@Rafa,您是否解决了上述问题,我正在尝试将相同的代码转换为Kotlin
abstract class MvpRecyclerListAdapter<M, P : BasePresenter<Any?, Any?>, VH : MvpViewHolder<P>> : MvpRecyclerAdapter<M, P, VH>() {...}