Java Reflection Primitive getPrimitiveClass(Class wrapper)

Here you can find the source of getPrimitiveClass(Class wrapper)

Description

get Primitive Class

License

Apache License

Parameter

Parameter Description
wrapper a parameter

Return

primitive clas or null

Declaration

public static Class getPrimitiveClass(Class wrapper) 

Method Source Code

//package com.java2s;
/*/*  ww w .  j  a  va 2  s.co  m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.util.HashMap;

public class Main {
    private static HashMap loadClassMap = new HashMap();

    /**
     * @param wrapper
     * @return primitive clas or null
     */
    public static Class getPrimitiveClass(Class wrapper) {
        if (wrapper == Integer.class)
            return int.class;
        else if (wrapper == Short.class)
            return short.class;
        else if (wrapper == Boolean.class)
            return boolean.class;
        else if (wrapper == Byte.class)
            return byte.class;
        else if (wrapper == Long.class)
            return long.class;
        else if (wrapper == Double.class)
            return double.class;
        else if (wrapper == Float.class)
            return float.class;
        else if (wrapper == Character.class)
            return char.class;

        return null;
    }

    /**
     * @param name of primitive type
     * @return primitive Class or null
     */
    public static Class getPrimitiveClass(String text) {
        return (Class) loadClassMap.get(text);
    }
}

Related

  1. getDefaultPrimitiveValue(Class clazz)
  2. getDefaultValue(Class primitive)
  3. getDefaultValueForPrimitive(Class type)
  4. getNullOrPrimitiveDefault(Class to)
  5. getPrimitive(final String classname)
  6. getPrimitiveClass(Class wrapperClazz)
  7. getPrimitiveClass(Class boxedClass)
  8. getPrimitiveClass(String name)
  9. getPrimitiveClass(String primitiveClassName)