Android examples for java.lang.reflect:Class
this will return the init value with type name.
//package com.java2s; public class Main { /**/*from www . j a v a2 s. c o m*/ * this will return the init value with type name. */ public static String getInitValueWithType(Class<?> type) { if (byte.class.equals(type)) { return "(byte) 0"; } else if (short.class.equals(type)) { return "(short) 0"; } else if (int.class.equals(type)) { return "0"; } else if (long.class.equals(type)) { return "0l"; } else if (float.class.equals(type)) { return "0f"; } else if (double.class.equals(type)) { return "0d"; } else if (char.class.equals(type)) { return "'\\0'"; } else if (boolean.class.equals(type)) { return "false"; } else { return "(" + type.getCanonicalName() + ") null"; } } }