在Base Presenter中使用Generics与Mosby和Dagger 2

时间:2015-12-16 05:16:55

标签: java android dagger-2 mosby

我试图在Dagger 2中使用Mosby的MvpBasePresenter设置Base Presenter我有以下基本组件:

public interface BaseViewComponent<V extends BaseView, P extends BasePresenter> {
    void injectView(V object);

    void injectPresenter(P object);

    P getPresenter();
}

使用以下BasePresenter

public class BasePresenter <V extends BaseView> extends MvpBasePresenter {
    @Inject public BasePresenter () {

    }
}

以及以下BaseActivity

public abstract class BaseActivity<P extends BasePresenter, C extends BaseViewComponent> extends MvpActivity implements BaseView<P> {

@Inject C mComponent;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getViewContentId() != 0) {
        setContentView(getViewContentId());
        ButterKnife.bind(this);
    }

}

@Override
public P createPresenter() {
    return mComponent.getPresenter();
}
}

由于某种原因,即使组件getPresenter返回P,创建演示者也显示为返回类型BasePresenter而不是P类型。任何人都有任何见解?这是一个好主意吗?

1 个答案:

答案 0 :(得分:0)

我的初步猜测如下,类似于this

bla-bla-bla