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 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(com.google.inject.spi.Element).

    Since:
    4.0
    • Method Detail

      • getKey

        Key<T> getKey()
        Returns the Key for this binding.
      • getAlternateKeys

        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<javax.inject.Provider<V>>.
        Since:
        4.2.3
      • 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 and 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.