Top Description Methods
com.google.inject.multibindings

public Interface OptionalBinderBinding<T>

Known Direct Implementers
com.google.inject.internal.RealOptionalBinder.JavaOptionalProvider, com.google.inject.internal.RealOptionalBinder.RealOptionalKeyProvider
Type Parameters
<T>
The fully qualified type of the optional binding, including Optional. For example: Optional<String>.
Imports
com.google.inject.Binding, .Key, com.google.inject.spi.Element, .Elements, java.util.Set

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 the Optional<V> key. Injectable types can be discovered using getKey (which will return the Optional<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 using containsElement.

Author
[email protected] (Sam Berlin)
Since
4.0

Method Summary

Modifier and TypeMethod and Description
public 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.

public Binding<?>
getActualBinding()

Returns the actual binding (set by OptionalBinder#setBinding) or null if not set.

public Set<Key<?>>
getAlternateKeys()

Returns the keys of other bindings that represent this OptionalBinder.

public Binding<?>
getDefaultBinding()

Returns the default binding (set by OptionalBinder#setDefault) if one exists or null if no default binding is set.

public Key<T>
getKey()

Returns the Key for this binding.

Method Detail

containsElementback to summary
public 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 and Elements#getElements. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwise getDefaultBinding and getActualBinding are better options.

getActualBindingback to summary
public Binding<?> getActualBinding()

Returns the actual binding (set by OptionalBinder#setBinding) or null if not set. This will throw UnsupportedOperationException if it is called on an element retrieved from Elements#getElements.

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

getAlternateKeysback to summary
public Set<Key<?>> getAlternateKeys()

Returns the keys of other bindings that represent this OptionalBinder. This will return an entry for Optional<com.google.inject.Provider<V>> and Optional<jakarta.inject.Provider<V>>.

Since
4.2.3
getDefaultBindingback to summary
public Binding<?> getDefaultBinding()

Returns the default binding (set by 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.

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

getKeyback to summary
public Key<T> getKey()

Returns the Key for this binding.