public abstract class Key<T> extends Object
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
.
Modifier | Constructor and Description |
---|---|
protected |
Key()
Constructs a new key.
|
protected |
Key(Annotation annotation)
Constructs a new key.
|
protected |
Key(Class<? extends Annotation> annotationType)
Constructs a new key.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(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.
|
Annotation |
getAnnotation()
Gets the annotation.
|
Class<? extends Annotation> |
getAnnotationType()
Gets the annotation type.
|
TypeLiteral<T> |
getTypeLiteral()
Gets the key type.
|
int |
hashCode() |
String |
toString() |
protected Key(Class<? extends Annotation> annotationType)
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) {}
.
protected Key(Annotation annotation)
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()) {}
.
protected Key()
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>() {}
.
public TypeLiteral<T> getTypeLiteral()
public Class<? extends Annotation> getAnnotationType()
public Annotation getAnnotation()
public static <T> Key<T> get(Class<T> type, Class<? extends Annotation> annotationType)
public static <T> Key<T> get(Class<T> type, Annotation annotation)
public static Key<?> get(Type type, Class<? extends Annotation> annotationType)
public static Key<?> get(Type type, Annotation annotation)
public static <T> Key<T> get(TypeLiteral<T> typeLiteral)
public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Class<? extends Annotation> annotationType)
public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Annotation annotation)
Copyright © 2013. All Rights Reserved.