public class TypeReference<T>
extends java.lang.Object
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 type literal for List<String>, you can
create an empty anonymous inner class:
TypeReference<List<String>> list = new TypeReference<List<String>>() {};
This syntax cannot be used to create type literals that have wildcard
parameters, such as Class<?> or List<? extends CharSequence>.| Modifier and Type | Field and Description |
|---|---|
(package private) static java.util.concurrent.ConcurrentMap<java.lang.reflect.Type,java.lang.reflect.Type> |
classTypeCache |
protected java.lang.reflect.Type |
type |
| Modifier | Constructor and Description |
|---|---|
protected |
TypeReference()
Constructs a new type literal.
|
protected |
TypeReference(java.lang.reflect.Type... actualTypeArguments) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.reflect.Type |
getType()
Gets underlying
Type instance. |
private java.lang.reflect.Type |
handlerParameterizedType(java.lang.reflect.ParameterizedType type,
java.lang.reflect.Type[] actualTypeArguments,
int actualIndex) |
static java.lang.reflect.Type |
intern(ParameterizedTypeImpl type) |
static java.util.concurrent.ConcurrentMap<java.lang.reflect.Type,java.lang.reflect.Type> classTypeCache
protected final java.lang.reflect.Type type
protected TypeReference()
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.
protected TypeReference(java.lang.reflect.Type... actualTypeArguments)
private java.lang.reflect.Type handlerParameterizedType(java.lang.reflect.ParameterizedType type,
java.lang.reflect.Type[] actualTypeArguments,
int actualIndex)
public java.lang.reflect.Type getType()
Type instance.public static java.lang.reflect.Type intern(ParameterizedTypeImpl type)