|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.inject.Key<T>
public abstract class Key<T>
Binding key. A type token and a name. Matches the type and name (Inject.value()
) at a point of injection.
For example, new Key<List<String>>("cities") {} will match:
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_NAME
Default binding name. |
Constructor Summary | |
---|---|
protected |
Key()
Convenience method. |
protected |
Key(java.lang.String name)
Constructs a new key. |
Method Summary | ||
---|---|---|
boolean |
equals(java.lang.Object o)
|
|
static
|
get(java.lang.Class<T> type)
Gets a key for a Class . |
|
static Key<?> |
get(java.lang.reflect.Type type)
Gets a key for a type. |
|
static
|
get(TypeToken<T> typeToken)
Gets a key for a type token. |
|
java.lang.String |
getName()
Gets the binding name. |
|
TypeToken<T> |
getTypeToken()
Gets token representing the type to be injected. |
|
boolean |
hasDefaultName()
Returns true if this key has the default name. |
|
int |
hashCode()
|
|
Key<T> |
named(java.lang.String name)
Returns a new key with the same type as this key and the given name, |
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_NAME
Constructor Detail |
---|
protected Key(java.lang.String name)
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
named "bar":
new Key<Foo>("bar") {}
.
protected Key()
Key(String)
with
DEFAULT_NAME
.
Method Detail |
---|
public boolean hasDefaultName()
true
if this key has the default name.
public Key<T> named(java.lang.String name)
public TypeToken<T> getTypeToken()
public java.lang.String getName()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static <T> Key<T> get(java.lang.Class<T> type)
Class
. Defaults name to DEFAULT_NAME
.
public static Key<?> get(java.lang.reflect.Type type)
DEFAULT_NAME
.
public static <T> Key<T> get(TypeToken<T> typeToken)
DEFAULT_NAME
.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |