Java Reflection Primitive convertPrimitiveToObjectClass(Class clazz)

Here you can find the source of convertPrimitiveToObjectClass(Class clazz)

Description

The class equivalent of (manual) autoboxing.

License

Apache License

Parameter

Parameter Description
clazz a parameter

Declaration

public static Class<?> convertPrimitiveToObjectClass(Class<?> clazz) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static final Map<Class<?>, Class<?>> primitiveToObjectClassMap = new HashMap<Class<?>, Class<?>>();

    /**/*from w ww  .java 2s  . co m*/
     * The class equivalent of (manual) autoboxing.
     *
     * @param clazz
     * @return
     */
    public static Class<?> convertPrimitiveToObjectClass(Class<?> clazz) {
        if (isPrimitiveClass(clazz)) {
            return primitiveToObjectClassMap.get(clazz);
        }
        return clazz;
    }

    /**
     * Determines whether the given clazz is a primitive class.
     *
     * @param clazz
     * @return
     */
    public static boolean isPrimitiveClass(Class<?> clazz) {
        return primitiveToObjectClassMap.containsKey(clazz);
    }
}

Related

  1. addPrimitiveToWrapperRelation(Class primitiveClass, Class wrapperClass)
  2. calculateDistancePrimitive(Class a, Class b)
  3. canCoerceLiteralNumberExpr(Class type)
  4. castToPrimitive(Object start, Class prim)
  5. convertPrimitiveToWrapper(Class clazz)
  6. convertPrimitiveToWrapper(Class clazz)
  7. convertToPrimitive(Class type)
  8. convertWrapperToPrimitive(Class clazz)