Package com.azure.core.util.serializer
Class TypeReference<T>
java.lang.Object
com.azure.core.util.serializer.TypeReference<T>
- Type Parameters:
T- The type being represented.
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TypeReference<T> createInstance(Class<T> clazz) Returns theClassrepresenting instance of theTypeReferencecreated.Returns theTyperepresentingT.
-
Constructor Details
-
TypeReference
public TypeReference()Constructs a newTypeReferencewhich maintains generic information.- Throws:
IllegalArgumentException- If the reference is constructed without type information.
-
-
Method Details
-
getJavaType
Returns theTyperepresentingT.- Returns:
- The
TyperepresentingT.
-
createInstance
Creates and instance ofTypeReferencewhich maintains the genericTof the passedClass.This method will cache the instance of
TypeReferenceusing the passedClassas the key. This is meant to be used with non-generic types such as primitive object types and POJOs, notMap<String, Object>orList<Integer>parameterized types.- Type Parameters:
T- The generic type.- Parameters:
clazz-Classthat contains generic information used to create theTypeReference.- Returns:
- Either the cached or new instance of
TypeReference.
-
getJavaClass
Returns theClassrepresenting instance of theTypeReferencecreated.- Returns:
- The
Classrepresenting instance of theTypeReferencecreated using thecreateInstance(Class), otherwise returnsnull.
-