Java Primitive Type Create toPrimitiveType(Class c)

Here you can find the source of toPrimitiveType(Class c)

Description

to Primitive Type

License

Open Source License

Declaration

public static Class<?> toPrimitiveType(Class<?> c) 

Method Source Code

//package com.java2s;

public class Main {
    public static Class<?> toPrimitiveType(Class<?> c) {

        if (c == null || c.isPrimitive())
            return c;

        // In descending order of likelihood...
        if (c.equals(Void.class))
            return c;
        else if (c.equals(Boolean.class))
            return Boolean.TYPE;
        else if (c.equals(Integer.class))
            return Integer.TYPE;
        else if (c.equals(Double.class))
            return Double.TYPE;
        else if (c.equals(Long.class))
            return Long.TYPE;
        else if (c.equals(Character.class))
            return Character.TYPE;
        else if (c.equals(Byte.class))
            return Byte.TYPE;
        else if (c.equals(Short.class))
            return Short.TYPE;
        else if (c.equals(Float.class))
            return Float.TYPE;
        else {//from  w  ww .j a  va  2s.c  om
            assert false : "It seems a new-fangled primitive type has been invented called " + c.getName();
            return c;
        }
    }

    /**
     * Returns true if obj1 and obj2 are both null, or if obj1.equals(obj2). Else returns false.
     * 
     * @param obj1
     * @param obj2
     * @return boolean
     */
    public static boolean equals(Object obj1, Object obj2) {

        if (obj1 == obj2)
            return true;
        if (obj1 == null || obj2 == null)
            return false;
        return obj1.equals(obj2);
    }
}

Related

  1. toPrimitiveClass(Class wrapperClass)
  2. toPrimitiveDouble(Double d)
  3. toPrimitiveInt(Integer value)
  4. toPrimitiveInt(Object o)
  5. toPrimitiveNumber(String s)
  6. toPrimitiveType(Class cls)
  7. toPrimitiveType(Class type)
  8. toPrimitiveWrapper(Class type)
  9. toPrimitiveWrapper(String primitiveJson, Class clazz)