是否可以在Dagger 2中注入超类型?
如果我有这样的财产
@Inject
Wallet<Material>
以下内容可以提供帮助吗?
@Provides
Wallet<LeatherMaterial> provide()
{
return new Wallet<LeatherMaterial>
}
实际上,我应该改掉这个问题。它无法正常工作,并且出现错误,需要注入确切的电子钱包
我们有什么解决方法吗? 。 koin是否提供像这样的功能?
答案 0 :(得分:1)
是的,您需要明确。如果您的依赖图中某处已经有Wallet<LeatherMaterial>
,请在模块中添加以下内容:
@Binds abstract Wallet<Material> provide(Wallet<LeatherMaterial> leatherWaller);
否则,请继续:
@Provides static Wallet<Material> provide() {
return new Wallet<LeatherMaterial>(){ /* ... */ };
}