Guice @Nullable注释 [英] Guice @Nullable annotation
本文介绍了Guice @Nullable注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的服务中,我有一个带 @Inject
的受保护构造函数,其中一个参数(提供者) @Nullable
。我得到的任何想法
In my service, I have a protected constructor with @Inject
and one of the parameters (provider) @Nullable
. Any ideas why I am getting
com.google.inject.CreationException: Guice creation errors:
1) No implementation for [[service]] was bound.
? Guice是3.0pre1, @Nullable
是我们的。
? Guice is 3.0pre1, @Nullable
is ours.
推荐答案
@Nullable
与 @Inject(optional = true)不一样
...我想如果你想注入 null
,你需要 bind(Service.class).toProvider(Providers。< Service> of(null))
或以其他方式拥有某种可能返回的提供者绑定 null
。
@Nullable
isn't the same as @Inject(optional=true)
... I think if you want to inject null
, you need to bind(Service.class).toProvider(Providers.<Service>of(null))
or to otherwise have some kind of provider bound that may return null
.
这篇关于Guice @Nullable注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文