Class Primitives

java.lang.Object
org.mockito.internal.util.Primitives

public final class Primitives extends Object
  • Method Details

    • primitiveTypeOf

      public static <T> Class<T> primitiveTypeOf(Class<T> clazz)
      Returns the primitive type of the given class.

      The passed class can be any class : boolean.class, Integer.class in witch case this method will return boolean.class, even SomeObject.class in which case null will be returned.

      Type Parameters:
      T - The type
      Parameters:
      clazz - The class from which primitive type has to be retrieved
      Returns:
      The primitive type if relevant, otherwise null
    • isPrimitiveOrWrapper

      public static boolean isPrimitiveOrWrapper(Class<?> type)
      Indicates if the given class is primitive type or a primitive wrapper.
      Parameters:
      type - The type to check
      Returns:
      true if primitive or wrapper, false otherwise.
    • isAssignableFromWrapper

      public static boolean isAssignableFromWrapper(Class<?> valueClass, Class<?> referenceType)
    • defaultValue

      public static <T> T defaultValue(Class<T> primitiveOrWrapperType)
      Returns the boxed default value for a primitive or a primitive wrapper.
      Parameters:
      primitiveOrWrapperType - The type to lookup the default value
      Returns:
      The boxed default values as defined in Java Language Specification, null if the type is neither a primitive nor a wrapper