Interface MultibinderBinding<T>
-
- Type Parameters:
T
- The fully qualified type of the set, including Set. For example:MultibinderBinding<Set<Boolean>>
public interface MultibinderBinding<T>
A binding for a Multibinder.Although Multibinders may be injected through a variety of generic types (
Set<V>
,Collection<Provider<V>>
, andSet<? extends V>
), a MultibinderBinding exists only on the Binding associated with theSet<V>
key. Injectable types can be discovered usinggetSetKey()
(which will return theSet<V>
key), orgetAlternateSetKeys()
(which will return the other keys that can inject this data). Other bindings can be validated to be derived from this MultibinderBinding usingcontainsElement(Element)
.- Since:
- 3.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 Multibinder uses the given Element.Set<Key<?>>
getAlternateSetKeys()
Returns the keys of other bindings that represent this set.List<Binding<?>>
getElements()
Returns all bindings that make up the set.TypeLiteral<?>
getElementTypeLiteral()
Returns the TypeLiteral that describes the type of elements in the set.Key<T>
getSetKey()
Returns the key for the set.boolean
permitsDuplicates()
Returns true if the multibinder permits duplicates.
-
-
-
Method Detail
-
getAlternateSetKeys
Set<Key<?>> getAlternateSetKeys()
Returns the keys of other bindings that represent this set. This will return an entry forCollection<com.google.inject.Provider<V>>
,Collection<javax.inject.Provider<V>>
, andSet<? extends V>
.- Since:
- 4.2.3
-
getElementTypeLiteral
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 aTypeLiteral<String>
.
-
getElements
List<Binding<?>> getElements()
Returns all bindings that make up the set. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationException
if it is called on an element retrieved fromElements.getElements(com.google.inject.Module...)
.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 typeList<Binding<String>>
.
-
permitsDuplicates
boolean permitsDuplicates()
Returns true if the multibinder permits duplicates. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationException
if it is called on a MultibinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.
-
containsElement
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 andElements.getElements(com.google.inject.Module...)
. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwisegetElements()
andpermitsDuplicates()
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()
andpermitsDuplicates()
.
-
-