unbox Wrapper object to primitive types - Android java.lang.reflect

Android examples for java.lang.reflect:Primitive Types

Description

unbox Wrapper object to primitive types

Demo Code


//package com.java2s;

public class Main {
    /**/* w  w  w .  jav  a2s  .  co  m*/
     * unbox Boolean
     */
    public static boolean unboxed(Boolean v) {
        return v == null ? false : v.booleanValue();
    }

    /**
     * unbox Character
     */
    public static char unboxed(Character v) {
        return v == null ? '\0' : v.charValue();
    }

    /**
     * unbox Byte
     */
    public static byte unboxed(Byte v) {
        return v == null ? 0 : v.byteValue();
    }

    /**
     * unbox Short
     */
    public static short unboxed(Short v) {
        return v == null ? 0 : v.shortValue();
    }

    /**
     * unbox Integer
     */
    public static int unboxed(Integer v) {
        return v == null ? 0 : v.intValue();
    }

    /**
     * unbox Long
     */
    public static long unboxed(Long v) {
        return v == null ? 0 : v.longValue();
    }

    /**
     * unbox Float
     */
    public static float unboxed(Float v) {
        return v == null ? 0 : v.floatValue();
    }

    /**
     * unbox Double
     */
    public static double unboxed(Double v) {
        return v == null ? 0 : v.doubleValue();
    }

    /**
     * unbox the given type
     */
    public static <T> T unboxed(T v) {
        return v;
    }
}

Related Tutorials