get Basic Type Null Value - Android java.lang.reflect

Android examples for java.lang.reflect:Field Value

Description

get Basic Type Null Value

Demo Code


//package com.java2s;

public class Main {
    public static Object getBasicTypeNullValue(Class<?> clazz) {
        if (clazz == Integer.TYPE) {
            return Integer.valueOf(0);
        }//  w w  w .  ja v  a 2  s.c  om
        if (clazz == Long.TYPE) {
            return Long.valueOf(0L);
        }
        if (clazz == Float.TYPE) {
            return Float.valueOf(0.0F);
        }
        if (clazz == Double.TYPE) {
            return Double.valueOf(0.0D);
        }
        if (clazz == Byte.TYPE) {
            return Byte.valueOf((byte) 0);
        }
        if (clazz == Short.TYPE) {
            return Short.valueOf((short) 0);
        }
        if (clazz == Character.TYPE) {
            return 0;
        }
        if (clazz == Boolean.TYPE) {
            return Boolean.FALSE;
        }

        return null;
    }
}

Related Tutorials