All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.inject.multibindings.MapKey Maven / Gradle / Ivy

package com.google.inject.multibindings;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Allows users define customized key type annotations for map bindings by annotating an annotation
 * of a {@code Map}'s key type. The custom key annotation can be applied to methods also annotated
 * with {@literal @}{@link ProvidesIntoMap}.
 *
 * 

A {@link StringMapKey} and {@link 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: * *

 * {@literal @}MapKey(unwrapValue = true)
 * {@literal @}Retention(RUNTIME)
 * public {@literal @}interface MyCustomEnumKey {
 *   MyCustomEnum value();
 * }
 * 
* * You can also use the whole annotation as the key, if {@code 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 {@code unwrapValue=true}, the value() type * will be the key type for injected map and the value() instances will be the keys values. */ @Documented @Target(ANNOTATION_TYPE) @Retention(RUNTIME) public @interface MapKey { /** * if {@code unwrapValue} is false, then the whole annotation will be the type and annotation * instances will be the keys. If {@code 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. */ boolean unwrapValue() default true; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy