Package com.google.gson.internal
Class $Gson$Types
- java.lang.Object
-
- com.google.gson.internal.$Gson$Types
-
public final class $Gson$Types extends Object
Static methods for working with types.- Author:
- Bob Lee, Jesse Wilson
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GenericArrayType
arrayOf(Type componentType)
Returns an array type whose elements are all instances ofcomponentType
.static Type
canonicalize(Type type)
Returns a type that is functionally equal but not necessarily equal according toObject.equals()
.static boolean
equals(Type a, Type b)
Returns true ifa
andb
are equal.static Type
getArrayComponentType(Type array)
Returns the component type of this array type.static Type
getCollectionElementType(Type context, Class<?> contextRawType)
Returns the element type of this collection type.static Type[]
getMapKeyAndValueTypes(Type context, Class<?> contextRawType)
Returns a two element array containing this map's key and value types in positions 0 and 1 respectively.static Class<?>
getRawType(Type type)
static ParameterizedType
newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArguments
torawType
and enclosed byownerType
.static Type
resolve(Type context, Class<?> contextRawType, Type toResolve)
static WildcardType
subtypeOf(Type bound)
Returns a type that represents an unknown type that extendsbound
.static WildcardType
supertypeOf(Type bound)
Returns a type that represents an unknown supertype ofbound
.static String
typeToString(Type type)
-
-
-
Method Detail
-
newParameterizedTypeWithOwner
public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArguments
torawType
and enclosed byownerType
.- Returns:
- a
serializable
parameterized type.
-
arrayOf
public static GenericArrayType arrayOf(Type componentType)
Returns an array type whose elements are all instances ofcomponentType
.- Returns:
- a
serializable
generic array type.
-
subtypeOf
public static WildcardType subtypeOf(Type bound)
Returns a type that represents an unknown type that extendsbound
. For example, ifbound
isCharSequence.class
, this returns? extends CharSequence
. Ifbound
isObject.class
, this returns?
, which is shorthand for? extends Object
.
-
supertypeOf
public static WildcardType supertypeOf(Type bound)
Returns a type that represents an unknown supertype ofbound
. For example, ifbound
isString.class
, this returns? super String
.
-
canonicalize
public static Type canonicalize(Type type)
Returns a type that is functionally equal but not necessarily equal according toObject.equals()
. The returned type isSerializable
.
-
getArrayComponentType
public static Type getArrayComponentType(Type array)
Returns the component type of this array type.- Throws:
ClassCastException
- if this type is not an array.
-
getCollectionElementType
public static Type getCollectionElementType(Type context, Class<?> contextRawType)
Returns the element type of this collection type.- Throws:
IllegalArgumentException
- if this type is not a collection.
-
getMapKeyAndValueTypes
public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType)
Returns a two element array containing this map's key and value types in positions 0 and 1 respectively.
-
-