Example usage for java.lang Class isPrimitive

List of usage examples for java.lang Class isPrimitive

Introduction

In this page you can find the example usage for java.lang Class isPrimitive.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isPrimitive();

Source Link

Document

Determines if the specified Class object represents a primitive type.

Usage

From source file:Main.java

public static void main(String[] args) {
    Main cl = new Main();
    Class c1Class = cl.getClass();

    // returns the Class object associated with an integer
    int k = 5;/*from  w  w w.ja  va 2 s . c  o m*/
    Class kClass = int.class;

    boolean retval1 = c1Class.isPrimitive();
    System.out.println(retval1);

    boolean retval2 = kClass.isPrimitive();
    System.out.println(retval2);
}

From source file:Main.java

private static boolean isBaseClass(Class clazz) {
    return clazz.isPrimitive() || clazz == Integer.class || clazz == Long.class || clazz == Float.class
            || clazz == Double.class || clazz == Boolean.class || clazz == String.class;
}

From source file:Main.java

private static TypeKind getKindOfType(Class<?> type) {
    if (!type.isPrimitive()) {
        return TypeKind.DECLARED;
    }/*from  w  w  w .  j  ava 2s  .  c om*/
    return TypeKind.valueOf(type.getName().toUpperCase());
}

From source file:Main.java

/**
 * Checks if a class is a Java type: Map, Collection,arrays, Number (extensions and primitives), String, Boolean..
 * //ww  w  .  j  a va  2 s.c  o m
 * @param clazz
 *          Class<?> to examine
 * @return true if clazz is Java type, false otherwise
 */
public static boolean isJavaType(Class<?> clazz) {
    if (clazz.isPrimitive())
        return true;
    else if (clazz.getName().startsWith("java.lang"))
        return true;
    else if (clazz.getName().startsWith("java.util"))
        return true;
    else if (clazz.isArray())
        return true;
    return false;
}

From source file:Main.java

public static Object getDefaultPrimiticeValue(Class clazz) {
    if (clazz.isPrimitive()) {
        return clazz == boolean.class ? false : 0;
    }/*w w w  .j av  a2 s  .  c  o  m*/
    return null;
}

From source file:Main.java

public static Class<?> convertFromPrimitiveType(Class<?> type) {
    if (!type.isPrimitive())
        return type;
    if (type == int.class)
        return Integer.class;
    if (type == long.class)
        return Long.class;
    if (type == float.class)
        return Float.class;
    if (type == double.class)
        return Double.class;
    if (type == short.class)
        return Short.class;
    if (type == byte.class)
        return Byte.class;
    if (type == char.class)
        return Character.class;
    if (type == boolean.class)
        return Boolean.class;
    throw new RuntimeException("Class not convertible from primitive: " + type.getName());
}

From source file:Main.java

public static Class<?> convertToPrimitiveType(Class<?> type) {
    if (type.isPrimitive())
        return type;
    if (type == Integer.class)
        return int.class;
    if (type == Long.class)
        return long.class;
    if (type == Float.class)
        return float.class;
    if (type == Double.class)
        return double.class;
    if (type == Short.class)
        return short.class;
    if (type == Byte.class)
        return byte.class;
    if (type == Character.class)
        return char.class;
    if (type == Boolean.class)
        return boolean.class;
    if (type == BigInteger.class)
        return long.class;
    if (type == BigDecimal.class)
        return double.class;
    if (type == Number.class)
        return double.class;
    throw new RuntimeException("Class not convertible to primitive: " + type.getName());
}

From source file:Main.java

static Class wrapperForPrimitiveType(Class type) {
    if (!type.isPrimitive()) {
        return type;
    }/*from w ww . jav  a2s.c  o m*/
    if (type == boolean.class) {
        return Boolean.class;
    }
    if (type == byte.class) {
        return Byte.class;
    }
    if (type == short.class) {
        return Short.class;
    }
    if (type == int.class) {
        return Integer.class;
    }
    if (type == long.class) {
        return Long.class;
    }
    if (type == float.class) {
        return Float.class;
    }
    if (type == double.class) {
        return Double.class;
    }
    if (type == char.class) {
        return Character.class;
    }
    throw new RuntimeException("Internal error");
}

From source file:Main.java

/**
 * Tells if a type is numerical; works both for primitive types and classes.
 * /*ww w . j  a  v  a 2  s.c o  m*/
 * @param type can't be {@code null}
 * 
 * @since 2.3.21
 */
public static boolean isNumerical(Class type) {
    return Number.class.isAssignableFrom(type)
            || type.isPrimitive() && type != Boolean.TYPE && type != Character.TYPE && type != Void.TYPE;
}

From source file:Main.java

public static String getDesc(Class<?> paramClass) {
    if (paramClass.isPrimitive()) {
        return getPrimitiveLetter(paramClass);
    }//from   w  ww.jav  a2  s.co  m
    if (paramClass.isArray()) {
        return "[" + getDesc(paramClass.getComponentType());
    }
    return "L" + getType(paramClass) + ";";
}