Java Reflection Primitive primitiveToWrapper(final Class cls)

Here you can find the source of primitiveToWrapper(final Class cls)

Description

Converts the specified primitive Class object to its corresponding wrapper Class object.

License

Open Source License

Parameter

Parameter Description
cls the class to convert, may be null

Return

the wrapper class for cls or cls if cls is not a primitive. null if null input.

Declaration

public static Class<?> primitiveToWrapper(final Class<?> cls) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;
import java.util.Map;

public class Main {
    /**/*from  w w w . j  ava2  s .  c  o  m*/
     * Maps primitive {@code Class}es to their corresponding wrapper
     * {@code Class}.
     */
    private static final Map<Class<?>, Class<?>> primitiveWrapperMap = new HashMap<Class<?>, Class<?>>();

    /**
     * <p>
     * Converts the specified primitive Class object to its corresponding
     * wrapper Class object.
     * </p>
     *
     * @param cls
     *            the class to convert, may be null
     * @return the wrapper class for {@code cls} or {@code cls} if {@code cls}
     *         is not a primitive. {@code null} if null input.
     */
    public static Class<?> primitiveToWrapper(final Class<?> cls) {
        Class<?> convertedClass = cls;
        if (cls != null && cls.isPrimitive()) {
            convertedClass = primitiveWrapperMap.get(cls);
        }
        return convertedClass;
    }
}

Related

  1. isWrapperAndPrimitivePair(Class c1, Class c2)
  2. isWrapperClass(Class clazz)
  3. isWrapperType(Class type)
  4. matchPrimitive(Class paramType, Object arg)
  5. primitiveArraysForName(String className)
  6. primitiveToWrapper(final Class cls)
  7. resolveClassPrimitiveAware(String className)
  8. resolvePrimitiveClassName(String name)
  9. resolvePrimitiveClassName(String name)