java.lang.Object
org.elasticsearch.injection.guice.Key<T>
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) { ... }
Key
supports generic types via subclassing just like TypeLiteral
.
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
static <T> Key
<T> Gets a key for an injection 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.final Annotation
Gets the annotation.final Class
<? extends Annotation> Gets the annotation type.final TypeLiteral
<T> Gets the key type.final int
hashCode()
final String
toString()
-
Constructor Details
-
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 Details
-
getTypeLiteral
Gets the key type. -
getAnnotationType
Gets the annotation type. -
getAnnotation
Gets the annotation. -
equals
-
hashCode
public final int hashCode() -
toString
-
get
Gets a key for an injection type. -
get
Gets a key for an injection type. -
get
Gets a key for an injection type and an annotation.
-