Class Key<T>
- java.lang.Object
-
- org.elasticsearch.common.inject.Key<T>
-
public class Key<T> extends Object
Binding key consisting of an injection type and an optional annotation. Matches the type and annotation at a point of injection.For example,
Key.get(Service.class, Transactional.class)will match:@Inject public void setService(@Transactional Service service) { ... }Keysupports generic types via subclassing just likeTypeLiteral.Keys do not differentiate between primitive types (int, char, etc.) and their corresponding wrapper types (Integer, Character, etc.). Primitive types will be replaced with their wrapper types when keys are created.
- Author:
- crazybob@google.com (Bob Lee)
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedKey()Constructs a new key.protectedKey(Annotation annotation)Constructs a new key.protectedKey(Class<? extends Annotation> annotationType)Constructs a new key.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static <T> Key<T>get(Class<T> type)Gets a key for an injection type.static <T> Key<T>get(Class<T> type, Annotation annotation)Gets a key for an injection type and an annotation.static <T> Key<T>get(Class<T> type, Class<? extends Annotation> annotationType)Gets a key for an injection type and an annotation type.static Key<?>get(Type type)Gets a key for an injection type.static Key<?>get(Type type, Annotation annotation)Gets a key for an injection type and an annotation.static Key<?>get(Type type, Class<? extends Annotation> annotationType)Gets a key for an injection type and an annotation type.static <T> Key<T>get(TypeLiteral<T> typeLiteral)Gets a key for an injection type.static <T> Key<T>get(TypeLiteral<T> typeLiteral, Annotation annotation)Gets a key for an injection type and an annotation.static <T> Key<T>get(TypeLiteral<T> typeLiteral, Class<? extends Annotation> annotationType)Gets a key for an injection type and an annotation type.AnnotationgetAnnotation()Gets the annotation.Class<? extends Annotation>getAnnotationType()Gets the annotation type.TypeLiteral<T>getTypeLiteral()Gets the key type.inthashCode()StringtoString()
-
-
-
Constructor Detail
-
Key
protected Key(Class<? extends Annotation> annotationType)
Constructs a new key. Derives the type from this class's type parameter.Clients create an empty anonymous subclass. Doing so embeds the type parameter in the anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
Example usage for a binding of type
Fooannotated with@Bar:new Key<Foo>(Bar.class) {}.
-
Key
protected Key(Annotation annotation)
Constructs a new key. Derives the type from this class's type parameter.Clients create an empty anonymous subclass. Doing so embeds the type parameter in the anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
Example usage for a binding of type
Fooannotated with@Bar:new Key<Foo>(new Bar()) {}.
-
Key
protected Key()
Constructs a new key. Derives the type from this class's type parameter.Clients create an empty anonymous subclass. Doing so embeds the type parameter in the anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
Example usage for a binding of type
Foo:new Key<Foo>() {}.
-
-
Method Detail
-
getTypeLiteral
public final TypeLiteral<T> getTypeLiteral()
Gets the key type.
-
getAnnotationType
public final Class<? extends Annotation> getAnnotationType()
Gets the annotation type.
-
getAnnotation
public final Annotation getAnnotation()
Gets the annotation.
-
get
public static <T> Key<T> get(Class<T> type, Class<? extends Annotation> annotationType)
Gets a key for an injection type and an annotation type.
-
get
public static <T> Key<T> get(Class<T> type, Annotation annotation)
Gets a key for an injection type and an annotation.
-
get
public static Key<?> get(Type type, Class<? extends Annotation> annotationType)
Gets a key for an injection type and an annotation type.
-
get
public static Key<?> get(Type type, Annotation annotation)
Gets a key for an injection type and an annotation.
-
get
public static <T> Key<T> get(TypeLiteral<T> typeLiteral)
Gets a key for an injection type.
-
get
public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Class<? extends Annotation> annotationType)
Gets a key for an injection type and an annotation type.
-
get
public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Annotation annotation)
Gets a key for an injection type and an annotation.
-
-