Reputation: 1741
So I have a BasePresenter class like so. BaseMvpView is an interface
open class BaseMvpPresenter<View : BaseMvpView> {
}
I am trying to create a BaseMvpActivity class which is parameterized with a BaseMvpPresenter like so:
abstract class BaseMvpActivity<T : BaseMvpPresenter> : BaseActivity(), BaseMvpView {
}
But I get the following error:
One type argument expected for class BaseMvpPresenter<View: BaseMvpView>
How do I properly declare this? I want to be able to use BaseMvpActivity as so:
abstract class BaseMvpActivity<T : BaseMvpPresenter<U>, U : BaseMvpView> : BaseActivity(), BaseMvpView {
abstract var presenter: T
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
presenter.onViewCreated(this)
}
override fun onDestroy() {
presenter.onViewDestroyed()
super.onDestroy()
}
}
Upvotes: 3
Views: 2533
Reputation: 991
You need to pass the parameter to the BaseMVPPresenter
. You can add a second parameter to your abstract class as follows
abstract class BaseMvpActivity<V: BaseMvpView, T : BaseMvpPresenter<V>> : BaseActivity(), BaseMvpView {
}
so lets say you're creating a view to show posts, then you would do something like this:
class Activity : BaseMVPActivity<PostsView, PostPresenter<PostView>() {
//Here comes your code
}
Hope this helps :)
Upvotes: 4