T - Represented typepublic class TypeToken<T> extends Object
T. Subclassing TypeToken allows for type information to be
preserved at runtime.
Example: To create a type literal for List<String>, you can create an empty anonymous
inner class:
TypeToken<List<String>> list = new TypeToken<List<String>>();
| Modifier | Constructor and Description |
|---|---|
protected |
TypeToken()
Creates a new type token for
T. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
Class<T> |
getRawType()
Returns the raw type for
T. |
Type |
getType()
Returns the generic type
T. |
int |
hashCode() |
static <T> TypeToken<T> |
of(Type type)
Returns a TypeLiteral for the
type. |
String |
toString() |
protected TypeToken()
T.IllegalArgumentException - if T is not provided or is a TypeVariablepublic static <T> TypeToken<T> of(Type type)
type.IllegalArgumentException - if type is null or if a raw type cannot be resolvedpublic final Class<T> getRawType()
T.
T is a Class, T itself is returned.
T is a ParameterizedType, the raw type is returned
T is a GenericArrayType, the raw type is returned
T is a TypeVariable or WildcardType, the raw type of the first
upper bound is returned
public final Type getType()
T.Copyright © 2011–2018. All rights reserved.