com.google.gson.reflect
Class TypeToken<T>

java.lang.Object
  extended by com.google.gson.reflect.TypeToken<T>

public abstract class TypeToken<T>
extends java.lang.Object

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.

Author:
Bob Lee, Sven Mawson

Method Summary
 boolean equals(java.lang.Object o)
          Method to test equality.
static
<T> TypeToken<T>
get(java.lang.Class<T> type)
          Gets type token for the given Class instance.
static TypeToken<?> get(java.lang.reflect.Type type)
          Gets type token for the given Type instance.
 java.lang.Class<? super T> getRawType()
          Gets the raw type.
 java.lang.reflect.Type getType()
          Gets underlying Type instance.
 int hashCode()
          Hashcode for this object.
 boolean isAssignableFrom(java.lang.Class<?> cls)
          Check if this type is assignable from the given class object.
 boolean isAssignableFrom(java.lang.reflect.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.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getRawType

public java.lang.Class<? super T> getRawType()
Gets the raw type.


getType

public java.lang.reflect.Type getType()
Gets underlying Type instance.


isAssignableFrom

public boolean isAssignableFrom(java.lang.Class<?> cls)
Check if this type is assignable from the given class object.


isAssignableFrom

public boolean isAssignableFrom(java.lang.reflect.Type from)
Check if this type is assignable from the given Type.


isAssignableFrom

public boolean isAssignableFrom(TypeToken<?> token)
Check if this type is assignable from the given type token.


hashCode

public int hashCode()
Hashcode for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
hashcode for this object.

equals

public boolean equals(java.lang.Object o)
Method to test equality.

Overrides:
equals in class java.lang.Object
Returns:
true if this object is logically equal to the specified object, false otherwise.

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.

get

public static TypeToken<?> get(java.lang.reflect.Type type)
Gets type token for the given Type instance.


get

public static <T> TypeToken<T> get(java.lang.Class<T> type)
Gets type token for the given Class instance.