Package com.google.gson.internal
Class $Gson$Types
java.lang.Object
com.google.gson.internal.$Gson$Types
Static methods for working with types.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
private static final class
The WildcardType interface supports multiple upper bounds and multiple lower bounds. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GenericArrayType
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()
.(package private) static void
checkNotPrimitive
(Type type) private static Class
<?> declaringClassOf
(TypeVariable<?> typeVariable) Returns the declaring class oftypeVariable
, ornull
if it was not declared by a class.private static boolean
static boolean
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.private static Type
getGenericSupertype
(Type context, Class<?> rawType, Class<?> supertype) Returns the generic supertype forsupertype
.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) private static Type
getSupertype
(Type context, Class<?> contextRawType, Class<?> supertype) Returns the generic form ofsupertype
.private static int
static ParameterizedType
newParameterizedTypeWithOwner
(Type ownerType, Class<?> rawType, Type... typeArguments) Returns a new parameterized type, applyingtypeArguments
torawType
and enclosed byownerType
.static boolean
requiresOwnerType
(Type rawType) static Type
private static Type
resolve
(Type context, Class<?> contextRawType, Type toResolve, Map<TypeVariable<?>, Type> visitedTypeVariables) private static Type
resolveTypeVariable
(Type context, Class<?> contextRawType, TypeVariable<?> unknown) static WildcardType
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)
-
Field Details
-
EMPTY_TYPE_ARRAY
-
-
Constructor Details
-
$Gson$Types
private $Gson$Types()
-
-
Method Details
-
newParameterizedTypeWithOwner
public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Class<?> rawType, Type... typeArguments) Returns a new parameterized type, applyingtypeArguments
torawType
and enclosed byownerType
.- Returns:
- a
serializable
parameterized type.
-
arrayOf
Returns an array type whose elements are all instances ofcomponentType
.- Returns:
- a
serializable
generic array type.
-
subtypeOf
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
Returns a type that represents an unknown supertype ofbound
. For example, ifbound
isString.class
, this returns? super String
. -
canonicalize
Returns a type that is functionally equal but not necessarily equal according toObject.equals()
. The returned type isSerializable
. -
getRawType
-
equal
-
equals
Returns true ifa
andb
are equal. -
typeToString
-
getGenericSupertype
Returns the generic supertype forsupertype
. For example, given a classIntegerSet
, the result for when supertype isSet.class
isSet<Integer>
and the result when the supertype isCollection.class
isCollection<Integer>
. -
getSupertype
Returns the generic form ofsupertype
. For example, if this isArrayList<String>
, this returnsIterable<String>
given the inputIterable.class
.- Parameters:
supertype
- a superclass of, or interface implemented by, this.
-
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
Returns a two element array containing this map's key and value types in positions 0 and 1 respectively. -
resolve
-
resolve
-
resolveTypeVariable
private static Type resolveTypeVariable(Type context, Class<?> contextRawType, TypeVariable<?> unknown) -
indexOf
-
declaringClassOf
Returns the declaring class oftypeVariable
, ornull
if it was not declared by a class. -
checkNotPrimitive
-
requiresOwnerType
Whether an owner type must be specified when constructing aParameterizedType
forrawType
.Note that this method might not require an owner type for all cases where Java reflection would create parameterized types with owner type.
-