Guava uses firstNonNull(a, b). It ensures that the result is never null, by checking that b is not null. I think the semantics of Guava's method is correct. I tend to think the method name isn't bad either.
Calling it nonNull(Object,Object) clashes with the existing nonNull(Object) method. Those two have nothing much to do with each other. Stephen On 6 October 2015 at 14:43, Roger Riggs <roger.ri...@oracle.com> wrote: > 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 >