Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * 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"; } } }