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.
  • Field Details

    • EMPTY_TYPE_ARRAY

      static final Type[] EMPTY_TYPE_ARRAY
  • Constructor Details

    • $Gson$Types

      private $Gson$Types()
  • Method Details

    • newParameterizedTypeWithOwner

      public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
      Returns a new parameterized type, applying typeArguments to rawType and enclosed by ownerType.
      Returns:
      a serializable parameterized type.
    • arrayOf

      public static GenericArrayType arrayOf(Type componentType)
      Returns an array type whose elements are all instances of componentType.
      Returns:
      a serializable generic array type.
    • subtypeOf

      public static WildcardType subtypeOf(Type bound)
      Returns a type that represents an unknown type that extends bound. For example, if bound is CharSequence.class, this returns ? extends CharSequence. If bound is Object.class, this returns ?, which is shorthand for ? extends Object.
    • supertypeOf

      public static WildcardType supertypeOf(Type bound)
      Returns a type that represents an unknown supertype of bound. For example, if bound is String.class, this returns ? super String.
    • canonicalize

      public static Type canonicalize(Type type)
      Returns a type that is functionally equal but not necessarily equal according to Object.equals(). The returned type is Serializable.
    • getRawType

      public static Class<?> getRawType(Type type)
    • equal

      private static boolean equal(Object a, Object b)
    • equals

      public static boolean equals(Type a, Type b)
      Returns true if a and b are equal.
    • typeToString

      public static String typeToString(Type type)
    • getGenericSupertype

      private static Type getGenericSupertype(Type context, Class<?> rawType, Class<?> supertype)
      Returns the generic supertype for supertype. For example, given a class IntegerSet, the result for when supertype is Set.class is Set<Integer> and the result when the supertype is Collection.class is Collection<Integer>.
    • getSupertype

      private static Type getSupertype(Type context, Class<?> contextRawType, Class<?> supertype)
      Returns the generic form of supertype. For example, if this is ArrayList<String>, this returns Iterable<String> given the input Iterable.class.
      Parameters:
      supertype - a superclass of, or interface implemented by, this.
    • 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.
    • resolve

      public static Type resolve(Type context, Class<?> contextRawType, Type toResolve)
    • resolve

      private static Type resolve(Type context, Class<?> contextRawType, Type toResolve, Map<TypeVariable<?>,Type> visitedTypeVariables)
    • resolveTypeVariable

      private static Type resolveTypeVariable(Type context, Class<?> contextRawType, TypeVariable<?> unknown)
    • indexOf

      private static int indexOf(Object[] array, Object toFind)
    • declaringClassOf

      private static Class<?> declaringClassOf(TypeVariable<?> typeVariable)
      Returns the declaring class of typeVariable, or null if it was not declared by a class.
    • checkNotPrimitive

      static void checkNotPrimitive(Type type)