微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 用Dagger注入泛型类

我的项目中有一个抽象的基类
public abstract class BaseActivity<T extends BasePresenter<? extends IBaseView>> implements IBaseView{

我试图注入一个泛型类:

@Inject protected T mPresenter;

有没有办法使匕首工作与这样一个通用的注射?匕首生成代码如下:

public final class BaseActivity$$InjectAdapter extends Binding<BaseActivity>
implements MembersInjector<BaseActivity> {
    private Binding<T> mPresenter;
}

然后失败,因为“T不能被解析为类型”.有什么办法让它生成一个

Binding<SomethingExtendingBasePresenter> mPresenter

在这种情况下?

解决方法

我知道的唯一方法是创建一个扩展你的泛型的新类.一种用于您感兴趣的每种类型.
public class Foo extends BaseActivity<SomethingExtendingBasePresenter> {
}

@Inject
Foo mFoo;

原文地址:https://www.jb51.cc/android/312527.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐