com.google.inject.multibindings

Annotation Type MapKey



  • @Documented
    @Target(value=ANNOTATION_TYPE)
    @Retention(value=RUNTIME)
    public @interface MapKey
    Allows users define customized key type annotations for map bindings by annotating an annotation of a Map's key type. The custom key annotation can be applied to methods also annotated with @ProvidesIntoMap.

    A StringMapKey and ClassMapKey are provided for convenience with maps whose keys are strings or classes. For maps with enums or primitive types as keys, you must provide your own MapKey annotation, such as this one for an enum:

     @MapKey(unwrapValue = true)
     @Retention(RUNTIME)
     public @interface MyCustomEnumKey {
       MyCustomEnum value();
     }
     
    You can also use the whole annotation as the key, if unwrapValue=false. When unwrapValue is false, the annotation type will be the key type for the injected map and the annotation instances will be the key values. If unwrapValue=true, the value() type will be the key type for injected map and the value() instances will be the keys values.

    Since:
    4.0
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element and Description
      boolean unwrapValue
      if unwrapValue is false, then the whole annotation will be the type and annotation instances will be the keys.
    • Element Detail

      • unwrapValue

        public abstract boolean unwrapValue
        if unwrapValue is false, then the whole annotation will be the type and annotation instances will be the keys. If unwrapValue is true, the value() type of key type annotation will be the key type for injected map and the value instances will be the keys.
        Default:
        true

Copyright © 2006–2018 Google, Inc.. All rights reserved.