What methods should go into a java.util.Objects class in JDK 7?

Paul Benedict pbenedict at apache.org
Sat Nov 14 17:28:07 PST 2009


I would like to propose adding this method:

/**
 * Selects the object if not {@code null}; otherwise fallsback to the
 * specified default object.
 *
 * @param object the object to test
 * @param defaultObject the default object
 * @return the object if not {@code null}; otherwise the default object
 */
public static Object defaultIfNull(Object object, Object defaultObject) {
    return (object != null) ? object : defaultObject;
}

Paul


More information about the core-libs-dev mailing list