T
- The fully qualified type of the optional binding, including Optional. For example:
Optional<String>
.public interface OptionalBinderBinding<T>
Although OptionalBinders may be injected through a variety of types T
, Optional<T>
, Optional<Provider<T>>
, etc..), an OptionalBinderBinding exists only on the
Binding associated with the Optional<T>
key. Other bindings can be validated to be
derived from this OptionalBinderBinding using containsElement(com.google.inject.spi.Element)
.
Modifier and Type | Method and Description |
---|---|
boolean |
containsElement(Element element)
Returns true if this OptionalBinder contains the given Element in order to build the optional
binding or uses the given Element in order to support building and injecting its data.
|
Binding<?> |
getActualBinding()
Returns the actual binding (set by
OptionalBinder.setBinding() ) or null if not set. |
Binding<?> |
getDefaultBinding()
Returns the default binding (set by
OptionalBinder.setDefault() ) if one exists or null if
no default binding is set. |
Key<T> |
getKey()
Returns the
Key for this binding. |
Binding<?> getDefaultBinding()
OptionalBinder.setDefault()
) if one exists or null if
no default binding is set. This will throw UnsupportedOperationException
if it is
called on an element retrieved from Elements.getElements(com.google.inject.Module...)
.
The Binding's type will always match the type Optional's generic type. For example, if
getKey returns a key of Optional<String>
, then this will always return a
Binding<String>
.
Binding<?> getActualBinding()
OptionalBinder.setBinding()
) or null if not set. This
will throw UnsupportedOperationException
if it is called on an element retrieved from
Elements.getElements(com.google.inject.Module...)
.
The Binding's type will always match the type Optional's generic type. For example, if
getKey returns a key of Optional<String>
, then this will always return a
Binding<String>
.
boolean containsElement(Element element)
Elements.getElements(com.google.inject.Module...)
. Usually this is only necessary if you are working with elements
retrieved from modules (without an Injector), otherwise getDefaultBinding()
and getActualBinding()
are better options.Copyright © 2006–2018 Google, Inc.. All rights reserved.