Class GsonTypes
java.lang.Object
com.google.gson.internal.GsonTypes
Static methods for working with types.
- Author:
- Bob Lee, Jesse Wilson
-
Method Summary
Modifier and TypeMethodDescriptionstatic GenericArrayTypeReturns an array type whose elements are all instances ofcomponentType.static Typecanonicalize(Type type) Returns a type that is functionally equal but not necessarily equal according toObject.equals().static booleanReturns true ifaandbare equal.static TypegetArrayComponentType(Type array) Returns the component type of this array type.static TypegetCollectionElementType(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 ParameterizedTypenewParameterizedTypeWithOwner(Type ownerType, Class<?> rawType, Type... typeArguments) Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.static booleanrequiresOwnerType(Type rawType) static Typestatic WildcardTypeReturns a type that represents an unknown type that extendsbound.static WildcardTypesupertypeOf(Type bound) Returns a type that represents an unknown supertype ofbound.static StringtypeToString(Type type)
-
Method Details
-
newParameterizedTypeWithOwner
public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Class<?> rawType, Type... typeArguments) Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.- Returns:
- a parameterized type.
-
arrayOf
Returns an array type whose elements are all instances ofcomponentType.- Returns:
- a generic array type.
-
subtypeOf
Returns a type that represents an unknown type that extendsbound. For example, ifboundisCharSequence.class, this returns? extends CharSequence. IfboundisObject.class, this returns?, which is shorthand for? extends Object. -
supertypeOf
Returns a type that represents an unknown supertype ofbound. For example, ifboundisString.class, this returns? super String. -
canonicalize
Returns a type that is functionally equal but not necessarily equal according toObject.equals(). -
getRawType
-
equals
-
typeToString
-
getArrayComponentType
Returns the component type of this array type.- Throws:
ClassCastException- if this type is not an array.
-
getCollectionElementType
Returns the element type of this collection type.- Throws:
IllegalArgumentException- if this type is not a collection.
-
getMapKeyAndValueTypes
-
resolve
-
requiresOwnerType
Whether an owner type must be specified when constructing aParameterizedTypeforrawType.Note that this method might not require an owner type for all cases where Java reflection would create parameterized types with owner type.
-