4

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.

ColinD
  • 108,630
  • 30
  • 201
  • 202
seminolas
  • 407
  • 8
  • 15
  • @Nullable is not enforced in any way, it's a note to the reader or code analysis tools. See http://stackoverflow.com/questions/14076296/nullable-annotation-usage – David Gladfelter Jun 08 '15 at 16:33
  • 2
    @DavidGladfelter actually Guice does mind `@Nullable` https://github.com/google/guice/wiki/UseNullable – orsg Feb 02 '16 at 07:37

1 Answers1

8

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

ColinD
  • 108,630
  • 30
  • 201
  • 202