I've defined the following base class with two generic types and using it two levels deep (for lack of a better phrase). Here's my use case.
abstract class BasePresenter<out M, out V> {
var model: M? = null
var view: WeakReference<V>? = null
fun setM(model: M?): Unit {
this.model = model
if (setupDone()) {
updateView()
}
}
fun bindView(view: V) {
this.view = WeakReference(view)
}
fun unbindView() {
this.view = null
}
abstract fun updateView()
fun view(): V? {
return if (view == null) null else view?.get()
}
fun setupDone(): Boolean {
return view() != null && model != null
}
}
I'm extending it using
open class VenueListPresenter: BasePresenter<Venue, VenueView>() {...}
Which works fine, as expected, but then I'm running into issues when I'm trying to use the VenuListPresenter
as a type parameter in a different class.
open class VenuesViewHolder(itemView: View): MvpViewHolder<VenueListPresenter>(itemView) {
This gives me an error stating that the expected argument in MvpViewHolder
is BasePresenter, and that what was found was a VenueListPresenter
. My VenueListPresenter
extends a BasePresenter<Venue, VenueView>
where Venue
and VenueView
are of type Any?
because by default they extend it. So why isn't it working?
MvpViewHolder is defined like so
abstract class MvpViewHolder<P>(itemView: View) : RecyclerView.ViewHolder(itemView) where P : BasePresenter<Any?, Any?>