Package com.alibaba.fastjson
Class TypeReference<T>
- java.lang.Object
-
- com.alibaba.fastjson.TypeReference<T>
-
public class TypeReference<T> extends Object
Represents a generic typeT. Java doesn't yet provide a way to represent generic types, so this class does. Forces clients to create a subclass of this class which enables retrieval the type information even at runtime.For example, to create a type literal for
List<String>, you can create an empty anonymous inner class:TypeReference<List<String>> list = new TypeReference<List<String>>() {};This syntax cannot be used to create type literals that have wildcard parameters, such asClass<?>orList<? extends CharSequence>.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTypeReference()Constructs a new type literal.protectedTypeReference(Type... actualTypeArguments)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TypegetType()Gets underlyingTypeinstance.static Typeintern(ParameterizedTypeImpl type)
-
-
-
Field Detail
-
type
protected final Type type
-
-
Constructor Detail
-
TypeReference
protected TypeReference()
Constructs a new type literal. Derives represented class from type parameter.Clients create an empty anonymous subclass. Doing so embeds the type parameter in the anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
-
TypeReference
protected TypeReference(Type... actualTypeArguments)
- Since:
- 1.2.9
-
-
Method Detail
-
getType
public Type getType()
Gets underlyingTypeinstance.
-
intern
public static Type intern(ParameterizedTypeImpl type)
-
-