Annotation Type MapKey


  • @Documented
    @Target(ANNOTATION_TYPE)
    @Retention(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 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

        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