Java Class to Primitive primitiveToWrapper(Class cls)

Here you can find the source of primitiveToWrapper(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(Class cls) 

Method Source Code

//package com.java2s;
/*//from  www . ja v  a  2s.c  o  m
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software");
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.util.*;

public class Main {
    /**
     * Maps primitive <code>Class</code>es to their corresponding wrapper <code>Class</code>.
     */
    private static Map primitiveWrapperMap = new HashMap();

    /**
     * <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</code> or <code>cls</code> if
     *         <code>cls</code> is not a primitive. <code>null</code> if null input.
     */
    public static Class primitiveToWrapper(Class cls) {
        Class convertedClass = cls;
        if (cls != null && cls.isPrimitive())
            convertedClass = (Class) primitiveWrapperMap.get(cls);

        return convertedClass;
    }
}

Related

  1. getPrimitiveDftValue(Class clazz)
  2. getPrimitiveTypeByWrapper(Class clazz)
  3. getPrimitiveWrapper(Class c)
  4. getWrapper(String primitiveClassName)
  5. getWrapperTypeByPrimitive(Class clazz)
  6. primitiveToWrapper(Class in)
  7. primitiveToWrapper(final Class p)
  8. toClass(String primitiveName)