Guice @Nullable annotation

吃可爱长大的小学妹 提交于 2019-12-31 00:41:09

问题


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 is 3.0pre1, @Nullable is ours.


回答1:


@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.



来源:https://stackoverflow.com/questions/4887196/guice-nullable-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!