@Test public void getDefaultPrimitiveValue() throws Exception { Assert.assertEquals((short) 0, ClassUtils.getDefaultPrimitiveValue(short.class)); Assert.assertEquals(0, ClassUtils.getDefaultPrimitiveValue(int.class)); Assert.assertEquals(0l, ClassUtils.getDefaultPrimitiveValue(long.class)); Assert.assertEquals(0d, ClassUtils.getDefaultPrimitiveValue(double.class)); Assert.assertEquals(0f, ClassUtils.getDefaultPrimitiveValue(float.class)); Assert.assertEquals((byte) 0, ClassUtils.getDefaultPrimitiveValue(byte.class)); Assert.assertEquals((char) 0, ClassUtils.getDefaultPrimitiveValue(char.class)); Assert.assertEquals(false, ClassUtils.getDefaultPrimitiveValue(boolean.class)); Assert.assertEquals(null, ClassUtils.getDefaultPrimitiveValue(Void.class)); Assert.assertEquals(null, ClassUtils.getDefaultPrimitiveValue(void.class)); Assert.assertEquals(null, ClassUtils.getDefaultPrimitiveValue(String.class)); }
public static Object getDefaultPrimitiveValue(Class clazz) { if (clazz == int.class) { return 0; } else if (clazz == boolean.class) { return false; } else if (clazz == long.class) { return 0L; } else if (clazz == byte.class) { return (byte) 0; } else if (clazz == double.class) { return 0d; } else if (clazz == short.class) { return (short) 0; } else if (clazz == float.class) { return 0f; } else if (clazz == char.class) { return (char) 0; } else { return null; } }
ClassUtils { public static Object getDefaultPrimitiveValue(Class clazz) { if (clazz == int.class) { return 0; } else if (clazz == boolean.class) { return false; } else if (clazz == long.class) { return 0L; } else if (clazz == byte.class) { return (byte) 0; } else if (clazz == double.class) { return 0d; } else if (clazz == short.class) { return (short) 0; } else if (clazz == float.class) { return 0f; } else if (clazz == char.class) { return (char) 0; } else { return null; } } }
ClassUtils { public static Object getDefaultPrimitiveValue(Class clazz) { if (clazz == int.class) { return 0; } else if (clazz == boolean.class) { return false; } else if (clazz == long.class) { return 0L; } else if (clazz == byte.class) { return (byte) 0; } else if (clazz == double.class) { return 0d; } else if (clazz == short.class) { return (short) 0; } else if (clazz == float.class) { return 0f; } else if (clazz == char.class) { return (char) 0; } else { return null; } }  }
ClassUtils { public static Object getDefaultPrimitiveValue(Class clazz) { if (clazz == int.class) { return 0; } else if (clazz == boolean.class) { return false; } else if (clazz == long.class) { return 0L; } else if (clazz == byte.class) { return (byte) 0; } else if (clazz == double.class) { return 0d; } else if (clazz == short.class) { return (short) 0; } else if (clazz == float.class) { return 0f; } else if (clazz == char.class) { return (char) 0; } else { 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); }
ClassUtils { public static Object getDefaultPrimitiveValue(Class clazz) { if (clazz == int.class) { return 0; } else if (clazz == boolean.class) { return false; } else if (clazz == long.class) { return 0L; } else if (clazz == byte.class) { return (byte) 0; } else if (clazz == double.class) { return 0d; } else if (clazz == short.class) { return (short) 0; } else if (clazz == float.class) { return 0f; } else if (clazz == char.class) { return (char) 0; } else { 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);  }