Search code examples
javaandroidgenericsmosby

How to add a base class to a mosby MVPActivity?


I am looking for a way to add a base class to a mosby MVPActivity. Let me explain what i need.

Usually when using mosby we would declare an activity like this:

public class LoginActivity extends MVPActivity<LoginView, LoginPresenter> {
//...
}

but i would like to add a base class so that i can do the calls like this:

public class LoginActivity extends BaseActivity<LoginView, LoginPresenter> {
//...
}

and then BaseActivity would be like this :

abstract class BaseActivity<T, P> extends MvpActivity<T extends MvpView, P> {
}

but this is not working as the IDE at compile time has an error saying that "extends MvpView" has unexpected bounds. So how can i add a base class to a mosby MVPActivity ?


Solution

  • You have to apply the generic parameters with your extended class definition and define it with the extension.

    abstract class BaseActivity<V extends MvpView, P extends MvpPresenter<V>>
           extends MvpActivity<V, P> { }