T - The type being represented.public abstract class TypeReference<T> extends Object
Code sample
// Construct a TypeReference<T> for a Java generic type.
// This pattern should only be used for generic types, for classes use the createInstance factory method.
TypeReference<Map<String, Object>> typeReference = new TypeReference<Map<String, Object>>() { };
// Construct a TypeReference<T> for a Java class. // This pattern should only be used for non-generic classes when possible, use the constructor for generic // class when possible. TypeReference<Integer> typeReference = TypeReference.createInstance(int.class);
| Constructor and Description |
|---|
TypeReference()
Constructs a new
TypeReference which maintains generic information. |
| Modifier and Type | Method and Description |
|---|---|
static <T> TypeReference<T> |
createInstance(Class<T> clazz)
|
Type |
getJavaType()
Returns the
Type representing T. |
public TypeReference()
TypeReference which maintains generic information.IllegalArgumentException - If the reference is constructed without type information.public Type getJavaType()
Type representing T.Type representing T.public static <T> TypeReference<T> createInstance(Class<T> clazz)
TypeReference which maintains the generic T of the passed Class.
This method will cache the instance of TypeReference using the passed Class as the key. This is
meant to be used with non-generic types such as primitive object types and POJOs, not Map<String, Object>
or List<Integer> parameterized types.
T - The generic type.clazz - Class that contains generic information used to create the TypeReference.TypeReference.Copyright © 2021 Microsoft Corporation. All rights reserved.