ClassUtils { public static <T> T getDefaultWrapperValue(Class<T> clazz) { if (clazz == Short.class) { return (T) Short.valueOf((short) 0); } else if (clazz == Integer.class) { return (T) Integer.valueOf(0); } else if (clazz == Long.class) { return (T) Long.valueOf(0L); } else if (clazz == Double.class) { return (T) Double.valueOf(0d); } else if (clazz == Float.class) { return (T) Float.valueOf(0f); } else if (clazz == Byte.class) { return (T) Byte.valueOf((byte) 0); } else if (clazz == Character.class) { return (T) Character.valueOf((char) 0); } else if (clazz == Boolean.class) { return (T) Boolean.FALSE; } return null; }  static Class forName(String className); static Class forName(String className, boolean initialize); static Class forName(String className, ClassLoader cl); static List<Method> getAllMethods(Class clazz); static List<Field> getAllFields(Class clazz); static T newInstance(Class<T> clazz); static T newInstanceWithArgs(Class<T> clazz, Class<?>[] argTypes, Object[] args); static Object getDefaultPrimitiveValue(Class clazz); static T getDefaultWrapperValue(Class<T> clazz); static String getMethodKey(String interfaceName, String methodName); static boolean isAssignableFrom(Class<?> interfaceClass, Class<?> implementClass);  }
@Test public void getDefaultWrapperValue() throws Exception { Assert.assertTrue((short) 0 == ClassUtils.getDefaultWrapperValue(Short.class)); Assert.assertTrue(0 == ClassUtils.getDefaultWrapperValue(Integer.class)); Assert.assertTrue(0l == ClassUtils.getDefaultWrapperValue(Long.class)); Assert.assertTrue(0d == ClassUtils.getDefaultWrapperValue(Double.class)); Assert.assertTrue(0f == ClassUtils.getDefaultWrapperValue(Float.class)); Assert.assertTrue((byte) 0 == ClassUtils.getDefaultWrapperValue(Byte.class)); Assert.assertTrue((char) 0 == ClassUtils.getDefaultWrapperValue(Character.class)); Assert.assertTrue(false == ClassUtils.getDefaultWrapperValue(Boolean.class)); Assert.assertEquals(null, ClassUtils.getDefaultWrapperValue(Void.class)); Assert.assertEquals(null, ClassUtils.getDefaultWrapperValue(void.class)); Assert.assertEquals(null, ClassUtils.getDefaultWrapperValue(String.class)); }