Class Primitives


  • public final class Primitives
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.Class<?>,​java.lang.Object> PRIMITIVE_OR_WRAPPER_DEFAULT_VALUES  
      private static java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVE_TYPES  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Primitives()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T defaultValue​(java.lang.Class<T> primitiveOrWrapperType)
      Returns the boxed default value for a primitive or a primitive wrapper.
      static boolean isAssignableFromWrapper​(java.lang.Class<?> valueClass, java.lang.Class<?> referenceType)  
      static boolean isPrimitiveOrWrapper​(java.lang.Class<?> type)
      Indicates if the given class is primitive type or a primitive wrapper.
      static <T> java.lang.Class<T> primitiveTypeOf​(java.lang.Class<T> clazz)
      Returns the primitive type of the given class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PRIMITIVE_TYPES

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVE_TYPES
      • PRIMITIVE_OR_WRAPPER_DEFAULT_VALUES

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Object> PRIMITIVE_OR_WRAPPER_DEFAULT_VALUES
    • Constructor Detail

      • Primitives

        private Primitives()
    • Method Detail

      • primitiveTypeOf

        public static <T> java.lang.Class<T> primitiveTypeOf​(java.lang.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​(java.lang.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​(java.lang.Class<?> valueClass,
                                                      java.lang.Class<?> referenceType)
      • defaultValue

        public static <T> T defaultValue​(java.lang.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