ObjectUtil { public static <T, S extends T> T defaultIfNull(T object, S defaultValue) { return object == null ? defaultValue : object; }  static T defaultIfNull(T object, S defaultValue); static boolean isEquals(Object object1, Object object2); static int hashCode(Object object); static int identityHashCode(Object object); static String identityToString(Object object); static String identityToString(Object object, String nullStr); static A appendIdentityToString(A buffer, Object object); static String toString(Object object); static String toString(Object object, String nullStr); static boolean isSameType(Object object1, Object object2); static boolean isEmpty(Object object); static boolean isNotEmpty(Object object); static boolean isNull(Object object); static boolean isNotNull(Object object); static boolean isAllNull(Object...objects); static boolean isAnyNull(Object...objects); static int nullNum(Object...objects); static StringBuilder appendIdentityToString(StringBuilder builder, Object object); static StringBuffer appendIdentityToString(StringBuffer buffer, Object object); static Object clone(Object array); static final String SERIAL_VERSION_UID; }
@Test public void defaultIfNull() { int[] ia = new int[0]; Class<?>[] ic = new Class[0]; String[] is = new String[0]; String s = ""; assertSame(ia, ObjectUtil.defaultIfNull(null, ia)); assertSame(ic, ObjectUtil.defaultIfNull(null, ic)); assertSame(is, ObjectUtil.defaultIfNull(null, is)); assertSame(s, ObjectUtil.defaultIfNull(null, s)); assertSame(s, ObjectUtil.defaultIfNull((Object) null, s)); assertEquals("123", ObjectUtil.defaultIfNull("123", s)); }