Top Description Methods
com.google.inject.multibindings

public Interface MultibinderBinding<T>

Known Direct Implementers
com.google.inject.internal.RealMultibinder.RealMultibinderProvider
Type Parameters
<T>
The fully qualified type of the set, including Set. For example: MultibinderBinding<Set<Boolean>>
Imports
com.google.inject.Binding, .Key, .TypeLiteral, com.google.inject.spi.Element, .Elements, java.util.List, .Set

A binding for a Multibinder.

Although Multibinders may be injected through a variety of generic types (Set<V>, Collection<Provider<V>>, and Set<? extends V> ), a MultibinderBinding exists only on the Binding associated with the Set<V> key. Injectable types can be discovered using getSetKey (which will return the Set<V> key), or getAlternateSetKeys (which will return the other keys that can inject this data). Other bindings can be validated to be derived from this MultibinderBinding using containsElement(Element).

Author
[email protected] (Sam Berlin)
Since
3.0

Method Summary

Modifier and TypeMethod and Description
public boolean
containsElement(Element element)

Returns true if this Multibinder uses the given Element.

public Set<Key<?>>
getAlternateSetKeys()

Returns the keys of other bindings that represent this set.

public List<Binding<?>>
getElements()

Returns all bindings that make up the set.

public TypeLiteral<?>
getElementTypeLiteral()

Returns the TypeLiteral that describes the type of elements in the set.

public Key<T>
getSetKey()

Returns the key for the set.

public boolean
permitsDuplicates()

Returns true if the multibinder permits duplicates.

Method Detail

containsElementback to summary
public boolean containsElement(Element element)

Returns true if this Multibinder uses the given Element. This will be true for bindings that derive the elements of the set and other bindings that Multibinder uses internally. This will work for MultibinderBindings 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 getElements and permitsDuplicates are better options.

If you need to introspect the details of the set, such as the values or if it permits duplicates, it is necessary to pass the elements through an Injector and use getElements() and permitsDuplicates().

getAlternateSetKeysback to summary
public Set<Key<?>> getAlternateSetKeys()

Returns the keys of other bindings that represent this set. This will return an entry for Collection<com.google.inject.Provider<V>>, Collection<jakarta.inject.Provider<V>>, and Set<? extends V>.

Since
4.2.3
getElementsback to summary
public List<Binding<?>> getElements()

Returns all bindings that make up the set. This is only supported on bindings returned from an injector. This will throw UnsupportedOperationException if it is called on an element retrieved from Elements#getElements.

The elements will always match the type Set's generic type. For example, if getSetKey returns a key of Set<String>, then this will always return a list of type List<Binding<String>>.

getElementTypeLiteralback to summary
public TypeLiteral<?> getElementTypeLiteral()

Returns the TypeLiteral that describes the type of elements in the set.

The elements will always match the type Set's generic type. For example, if getSetKey returns a key of Set<String>, then this will always return a TypeLiteral<String>.

getSetKeyback to summary
public Key<T> getSetKey()

Returns the key for the set.

permitsDuplicatesback to summary
public boolean permitsDuplicates()

Returns true if the multibinder permits duplicates. This is only supported on bindings returned from an injector. This will throw UnsupportedOperationException if it is called on a MultibinderBinding retrieved from Elements#getElements.