Trying to implement a simple MVP structure with Kotlin, here are my base classes:

abstract class BaseActivity<P : BasePresenter<BaseView>> : BaseView, AppCompatActivity() {
//...
}

abstract class BasePresenter<V : BaseView>  {
//...
}

interface BaseView {
//...
}

And trying to use this structure with

class DummyActivity : BaseActivity<DummyPresenter>(), DummyView.View {
//...
}

class DummyPresenter : BasePresenter<DummyView.View>(), DummyView.UserActionListener {
//...
}

interface DummyView {

interface View : BaseView {
    fun displayLoading()
}

interface UserActionListener {
    fun onButtonClicked()
 }
}

However I am getting an error in DummyActivity, BaseActivity() as:

error

I am assuming there is something to be fixed in BaseActivity about generics, however I can not figure out what.

Any help is appreciated, Thanks

1 Answers

1
César Chrétien On Best Solutions

First class in your first code block should be defined as

abstract class BaseActivity<P : BasePresenter<out BaseView>> : BaseView, AppCompatActivity() {
//...
}

Key being the out modifier on BaseView.