@Documented @Beta @Target(value=METHOD) public @interface BindsOptionalOf
Optional containers of values from bindings
that may or may not be present in the component.
If a module contains a method declaration like this:
@BindsOptionalOf abstract Foo optionalFoo();then any binding in the component can depend on an
Optional of Foo. If there is
no binding for Foo in the component, the Optional will be absent. If there is a
binding for Foo in the component, the Optional will be present, and its value
will be the value given by the binding for Foo.
A @BindsOptionalOf method:
abstract
void
@Inject-annotated constructor,
since such a type is always present
Other bindings may inject any of:
Optional<Foo>
Optional<Provider<Foo>>
Optional<Lazy<Foo>>
Optional<Provider<Lazy<Foo>>>
Explicit bindings for any of the above will conflict with a @BindsOptionalOf binding.
If the binding for Foo is a @Produces binding, then another @Produces
binding can depend on any of:
Optional<Foo>
Optional<Producer<Foo>>
Optional<Produced<Foo>>
You can inject either com.google.common.base.Optional or java.util.Optional.
Copyright © 2012���2017 The Dagger Authors. All rights reserved.