Interface OptionalBinderBinding<T>
-
- Type Parameters:
T
- The fully qualified type of the optional binding, including Optional. For example:Optional<String>
.
public interface OptionalBinderBinding<T>
A binding for a OptionalBinder.Although OptionalBinders may be injected through a variety of types
V
,Optional<V>
,Optional<Provider<V>>
, etc..), an OptionalBinderBinding exists only on the Binding associated with theOptional<V>
key. Injectable types can be discovered usinggetKey()
(which will return theOptional<V>
key), orgetAlternateKeys()
(which will return the other keys that can inject this data). Other bindings can be validated to be derived from this OptionalBinderBinding usingcontainsElement(com.google.inject.spi.Element)
.- Since:
- 4.0
- Author:
- sameb@google.com (Sam Berlin)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method 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 byOptionalBinder.setBinding()
) or null if not set.Set<Key<?>>
getAlternateKeys()
Returns the keys of other bindings that represent this OptionalBinder.Binding<?>
getDefaultBinding()
Returns the default binding (set byOptionalBinder.setDefault()
) if one exists or null if no default binding is set.Key<T>
getKey()
Returns theKey
for this binding.
-
-
-
Method Detail
-
getAlternateKeys
Set<Key<?>> getAlternateKeys()
Returns the keys of other bindings that represent this OptionalBinder. This will return an entry forOptional<com.google.inject.Provider<V>>
andOptional<javax.inject.Provider<V>>
.- Since:
- 4.2.3
-
getDefaultBinding
Binding<?> getDefaultBinding()
Returns the default binding (set byOptionalBinder.setDefault()
) if one exists or null if no default binding is set. This will throwUnsupportedOperationException
if it is called on an element retrieved fromElements.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 aBinding<String>
.
-
getActualBinding
Binding<?> getActualBinding()
Returns the actual binding (set byOptionalBinder.setBinding()
) or null if not set. This will throwUnsupportedOperationException
if it is called on an element retrieved fromElements.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 aBinding<String>
.
-
containsElement
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. This will work for OptionalBinderBinding retrieved from an injector andElements.getElements(com.google.inject.Module...)
. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwisegetDefaultBinding()
andgetActualBinding()
are better options.
-
-