RFR 9: 8138963 : java.lang.Objects new method to default to non-null

Roger Riggs Roger.Riggs at Oracle.com
Tue Oct 6 13:43:59 UTC 2015


Java.lang.Objects contains a number of convenience methods to make it 
easier to handle references that are null.
For example, toString(obj, nullDefault),

A new method is proposed to return the reference or a default value if 
the reference is null.
    static <T> T nonNull(T obj, T nullDefault);

Alternatives to the method name include
nonNullOrElse ( using the java.util.Optional name pattern) or
nonNullOrDefault

Please review and comment.

Webrev:
   http://cr.openjdk.java.net/~rriggs/webrev-object-non-null/

Issue:
   https://bugs.openjdk.java.net/browse/JDK-8138963

Thanks, Roger




More information about the core-libs-dev mailing list