Java Utililty Methods Reflection Primitive

List of utility methods to do Reflection Primitive

Description

The list of methods to do Reflection Primitive are organized into topic(s).

Method

voidaddPrimitiveToWrapperRelation(Class primitiveClass, Class wrapperClass)
add Primitive To Wrapper Relation
PRIMITIVE_TO_WRAPPERS_MAP.put(primitiveClass, wrapperClass);
WRAPPERS_TO_PRIMITIVE_MAP.put(wrapperClass, primitiveClass);
floatcalculateDistancePrimitive(Class a, Class b)
calculate Distance Primitive
if (b == Character.class || b == Boolean.class)
    return -1F;
if (a == Character.class)
    a = Short.class;
int indexA = PRIMITIVE_WIDENING.indexOf(a);
int indexB = PRIMITIVE_WIDENING.indexOf(b);
if (indexA < 0 || indexB < 0)
    return -1F;
...
booleancanCoerceLiteralNumberExpr(Class type)
can Coerce Literal Number Expr
final List<? extends Class<?>> classes = Arrays.asList(int.class, long.class, double.class);
return classes.contains(type);
TcastToPrimitive(Object start, Class prim)
cast To Primitive
try {
    if (start == null) {
        return (T) defaultPrimitiveValues.get(prim);
    if (start instanceof Boolean) {
        start = ((Boolean) start) ? 1 : 0;
    if (start instanceof Character) {
...
ClassconvertPrimitiveToObjectClass(Class clazz)
The class equivalent of (manual) autoboxing.
if (isPrimitiveClass(clazz)) {
    return primitiveToObjectClassMap.get(clazz);
return clazz;
ClassconvertPrimitiveToWrapper(Class clazz)
Gets the equivalent class to convert to if the given clazz is a primitive.
if (clazz == null || !clazz.isPrimitive())
    return clazz;
return (Class) primativeToWrapperMap.get(clazz);
ClassconvertPrimitiveToWrapper(Class clazz)
Checks whether a given class object is a primitive and returns its wrapper class (except for void where always the primitive class is used).
Class<?> result = clazz;
if (clazz.isPrimitive()) {
    return primitiveWrapperClasses.get(clazz.getName());
return result;
ClassconvertToPrimitive(Class type)
convert To Primitive
if (type == null || type.isPrimitive()) {
    throw new IllegalArgumentException(
            "Given class type is wrong. Either it is null or is a primitive. given-class[" + type + "]");
return wrapperToprimitives.get(type);
ClassconvertWrapperToPrimitive(Class clazz)
convert Wrapper To Primitive
Class<?> result = clazz;
if (!clazz.isPrimitive()) {
    return wrapperPrimitiveClasses.get(clazz.getName());
return result;
KcreateDefaultPrimitive(Class type)
Returns the default value (JLS 4.12.5) of a primitive type.
return type.cast(PRIMITIVE_DEFAULTS.get(type));