Class Primitives

java.lang.Object
com.google.gson.internal.Primitives

public final class Primitives extends Object
Contains static utility methods pertaining to primitive types and their corresponding wrapper types.
Author:
Kevin Bourrillion
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Returns true if this type is a primitive.
    static boolean
    Returns true if type is one of the nine primitive-wrapper types, such as Integer.
    static <T> Class<T>
    unwrap(Class<T> type)
    Returns the corresponding primitive type of type if it is a wrapper type; otherwise returns type itself.
    static <T> Class<T>
    wrap(Class<T> type)
    Returns the corresponding wrapper type of type if it is a primitive type; otherwise returns type itself.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isPrimitive

      public static boolean isPrimitive(Type type)
      Returns true if this type is a primitive.
    • isWrapperType

      public static boolean isWrapperType(Type type)
      Returns true if type is one of the nine primitive-wrapper types, such as Integer.
      See Also:
    • wrap

      public static <T> Class<T> wrap(Class<T> type)
      Returns the corresponding wrapper type of type if it is a primitive type; otherwise returns type itself. Idempotent.
           wrap(int.class) == Integer.class
           wrap(Integer.class) == Integer.class
           wrap(String.class) == String.class
       
    • unwrap

      public static <T> Class<T> unwrap(Class<T> type)
      Returns the corresponding primitive type of type if it is a wrapper type; otherwise returns type itself. Idempotent.
           unwrap(Integer.class) == int.class
           unwrap(int.class) == int.class
           unwrap(String.class) == String.class