T
- the referenced typepublic abstract class ParameterizedTypeReference<T>
extends java.lang.Object
Type
. In order to capture the generic type and retain it at runtime,
you need to create a subclass (ideally as anonymous inline class) as follows:
ParameterizedTypeReference<List<String>> typeRef = new ParameterizedTypeReference<List<String>>() {};
The resulting typeRef
instance can then be used to obtain a Type
instance that carries the captured parameterized type information at runtime.
For more information on "super type tokens" see the link to Neal Gafter's blog post.
Modifier and Type | Field and Description |
---|---|
private java.lang.reflect.Type |
type |
Modifier | Constructor and Description |
---|---|
protected |
ParameterizedTypeReference() |
private |
ParameterizedTypeReference(java.lang.reflect.Type type) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other) |
private static java.lang.Class<?> |
findParameterizedTypeReferenceSubclass(java.lang.Class<?> child) |
static <T> ParameterizedTypeReference<T> |
forType(java.lang.reflect.Type type)
Build a
ParameterizedTypeReference wrapping the given type. |
java.lang.reflect.Type |
getType() |
int |
hashCode() |
java.lang.String |
toString() |
protected ParameterizedTypeReference()
private ParameterizedTypeReference(java.lang.reflect.Type type)
public java.lang.reflect.Type getType()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static <T> ParameterizedTypeReference<T> forType(java.lang.reflect.Type type)
ParameterizedTypeReference
wrapping the given type.type
- a generic type (possibly obtained via reflection,
e.g. from Method.getGenericReturnType()
)ParameterizedTypeReference
-accepting methodsprivate static java.lang.Class<?> findParameterizedTypeReferenceSubclass(java.lang.Class<?> child)