TypeReference<T> Class
- java.
lang. Object - com.
azure. core. util. serializer. TypeReference<T>
- com.
Type Parameters
- T
The type being represented.
public abstract class TypeReference<T>
This class represents a generic Java type, retaining information about generics.
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 Summary
| Constructor | Description |
|---|---|
| TypeReference() |
Constructs a new TypeReference<T> which maintains generic information. |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
|
static
Type |
createInstance(Class<T> clazz)
Creates and instance of TypeReference<T> which maintains the generic |
| Class<T> |
getJavaClass()
Returns the Class representing instance of the TypeReference<T> created. |
| Type |
getJavaType()
Returns the Type representing |
Methods inherited from java.lang.Object
Constructor Details
TypeReference
public TypeReference()
Constructs a new TypeReference<T> which maintains generic information.
Method Details
createInstance
public static TypeReference<T> <T>createInstance(Class<T> clazz)
Creates and instance of TypeReference<T> which maintains the generic T of the passed Class.
This method will cache the instance of TypeReference<T> 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 or List parameterized types.
Parameters:
Returns:
getJavaClass
public Class<T> getJavaClass()
Returns the Class representing instance of the TypeReference<T> created.
Returns:
null.getJavaType
public Type getJavaType()
Returns the Type representing T.
Returns:
T.