T
- the referenced typepublic abstract class ParameterizedTypeReference<T> extends 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 | Constructor and Description |
---|---|
protected |
ParameterizedTypeReference() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
static <T> ParameterizedTypeReference<T> |
forType(Type type)
Build a
ParameterizedTypeReference wrapping the given type. |
Type |
getType() |
int |
hashCode() |
String |
toString() |
public Type getType()
public static <T> ParameterizedTypeReference<T> forType(Type type)
ParameterizedTypeReference
wrapping the given type.type
- a generic type (possibly obtained via reflection,
e.g. from Method.getGenericReturnType()
)ParameterizedTypeReference
-accepting methods