|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.inject.TypeLiteral<T>
public abstract class TypeLiteral<T>
Represents a generic type T
. Java doesn't yet provide a way to
represent generic types, so this class does. Forces clients to create a
subclass of this class which enables retrieval the type information
even at runtime.
For example, to create a TypeLiteral
for List<String>
,
you can create an empty anonymous inner class:
TypeLiteral<List<String>> listOfString = new TypeLiteral<List<String>>() {};
Assumes Type
implements equals()
and hashCode()
as a value (as opposed to identity) comparison.
Constructor Summary | |
---|---|
protected |
TypeLiteral()
Constructs a new type literal. |
Method Summary | ||
---|---|---|
boolean |
equals(java.lang.Object o)
|
|
static
|
get(java.lang.Class<T> type)
Gets type literal for the given Class instance. |
|
static TypeLiteral<?> |
get(java.lang.reflect.Type type)
Gets type literal for the given Type instance. |
|
java.lang.reflect.Type |
getType()
Gets underlying Type instance. |
|
int |
hashCode()
|
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected TypeLiteral()
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.
For example: TypeLiteral<List<String>> t = new
TypeLiteral<List<String>>() {};
Method Detail |
---|
public java.lang.reflect.Type getType()
Type
instance.
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 TypeLiteral<?> get(java.lang.reflect.Type type)
Type
instance.
public static <T> TypeLiteral<T> get(java.lang.Class<T> type)
Class
instance.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |