Class Key<T>
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
ModifierConstructorDescriptionprotected
Key()
Constructs a new key.protected
annotation)
Constructs a new key.protected
<? extends > annotationType)
Constructs a new key. -
Method Summary
Modifier and TypeMethodDescriptionboolean
o)
static <T> Key<T>
<T> type)
Gets a key for an injection type.static <T> Key<T>
<T> type, annotation)
Gets a key for an injection type and an annotation.static <T> Key<T>
<T> type, <? extends > annotationType)
Gets a key for an injection type and an annotation type.static Key<?>
type)
Gets a key for an injection type.static Key<?>
type, annotation)
Gets a key for an injection type and an annotation.static Key<?>
type, <? extends > 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)
Gets a key for an injection type and an annotation.static <T> Key<T>
get(TypeLiteral<T> typeLiteral, <? extends > annotationType)
Gets a key for an injection type and an annotation type.Gets the annotation.<? extends >
Gets the annotation type.Gets the key type.int
hashCode()
toString()
Methods inherited from class java.lang.
, , , , , , ,
-
Constructor Details
-
Key
protected Key(<? extends > 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
Foo
annotated with@Bar
:new Key<Foo>(Bar.class) {}
. -
Key
protected Key( 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
Foo
annotated 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 Details
-
getTypeLiteral
Gets the key type. -
getAnnotationType
public final <? extends > getAnnotationType()Gets the annotation type. -
getAnnotation
public final getAnnotation()Gets the annotation. -
equals
public final boolean equals( o)- Overrides:
in class
-
hashCode
public final int hashCode()- Overrides:
in class
-
toString
public final toString()- Overrides:
in class
-
get
public static <T> <T> type)Gets a key for an injection type. -
get
public static <T> <T> type, <? extends > annotationType)Gets a key for an injection type and an annotation type. -
get
public static <T> <T> type, annotation)Gets a key for an injection type and an annotation. -
get
public static type)Gets a key for an injection type. -
get
public static type, <? extends > annotationType)Gets a key for an injection type and an annotation type. -
get
public static type, annotation)Gets a key for an injection type and an annotation. -
get
Gets a key for an injection type. -
get
Gets a key for an injection type and an annotation type. -
get
Gets a key for an injection type and an annotation.
-