Convert BOXED version of class to it unboxed version. - Android java.lang.reflect

Android examples for java.lang.reflect:Class

Description

Convert BOXED version of class to it unboxed version.

Demo Code


//package com.java2s;
import android.support.annotation.NonNull;

public class Main {
    /**//from   w ww . ja  va2  s .  com
     * Convert BOXED version of class to it unboxed version.
     *
     * @param type reflection type to check and convert.
     */
    public static Class<?> unboxing(@NonNull final Class<?> type) {
        if (Boolean.class.equals(type))
            return boolean.class;
        if (Character.class.equals(type))
            return char.class;
        if (Byte.class.equals(type))
            return byte.class;
        if (Short.class.equals(type))
            return short.class;
        if (Integer.class.equals(type))
            return int.class;
        if (Long.class.equals(type))
            return long.class;
        if (Float.class.equals(type))
            return float.class;
        if (Double.class.equals(type))
            return double.class;

        return type;
    }
}

Related Tutorials