|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.gson.reflect.TypeToken<T>
public abstract class TypeToken<T>
Represents a generic type T
.
You can use this class to get the generic type for a class. For example,
to get the generic type for Collection<Foo>
, you can use:
Type typeOfCollectionOfFoo = new TypeToken<Collection<Foo>>(){}.getType()
Assumes Type
implements equals()
and hashCode()
as a value (as opposed to identity) comparison.
Also implements isAssignableFrom(Type)
to check type-safe
assignability.
Constructor Summary | |
---|---|
protected |
TypeToken()
Constructs a new type token. |
Method Summary | ||
---|---|---|
boolean |
equals(Object o)
Method to test equality. |
|
static
|
get(Class<T> type)
Gets type token for the given Class instance. |
|
static TypeToken<?> |
get(Type type)
Gets type token for the given Type instance. |
|
Class<? super T> |
getRawType()
Gets the raw type. |
|
Type |
getType()
Gets underlying Type instance. |
|
int |
hashCode()
Hashcode for this object. |
|
boolean |
isAssignableFrom(Class<?> cls)
Check if this type is assignable from the given class object. |
|
boolean |
isAssignableFrom(Type from)
Check if this type is assignable from the given Type. |
|
boolean |
isAssignableFrom(TypeToken<?> token)
Check if this type is assignable from the given type token. |
|
String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected TypeToken()
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:
TypeToken<List<String>> t = new TypeToken<List<String>>(){}
Method Detail |
---|
public Class<? super T> getRawType()
public Type getType()
Type
instance.
public boolean isAssignableFrom(Class<?> cls)
public boolean isAssignableFrom(Type from)
public boolean isAssignableFrom(TypeToken<?> token)
public int hashCode()
hashCode
in class Object
public boolean equals(Object o)
equals
in class Object
public String toString()
toString
in class Object
public static TypeToken<?> get(Type type)
Type
instance.
public static <T> TypeToken<T> get(Class<T> type)
Class
instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |