get unboxed type of class. - Android java.lang.reflect

Android examples for java.lang.reflect:Primitive Types

Description

get unboxed type of class.

Demo Code


//package com.java2s;

public class Main {
    /**//from  w  ww.j av a 2  s.c o m
     * get unboxed type of class.
     */
    public static Class<?> getUnboxedClass(Class<?> type) {
        if (type == Boolean.class) {
            return boolean.class;
        } else if (type == Character.class) {
            return char.class;
        } else if (type == Byte.class) {
            return byte.class;
        } else if (type == Short.class) {
            return short.class;
        } else if (type == Integer.class) {
            return int.class;
        } else if (type == Long.class) {
            return long.class;
        } else if (type == Float.class) {
            return float.class;
        } else if (type == Double.class) {
            return double.class;
        } else {
            return type;
        }
    }
}

Related Tutorials