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

Chris Hegarty chris.hegarty at oracle.com
Thu Oct 8 08:29:18 UTC 2015

On 7 Oct 2015, at 23:44, Stephen Colebourne <scolebourne at joda.org> wrote:

> On 7 October 2015 at 23:24, Roger Riggs <Roger.Riggs at oracle.com> wrote:
>> Please consider and comment:
>>    <T> T nonNullOf(T obj, T defaultObj);
>>    <T> T nonNullOf(T, obj, Supplier<T> defaultSupplier);
>> Details are in the updated webrev:
>>     http://cr.openjdk.java.net/~rriggs/webrev-object-non-null/
> I think I can live with that name.


> The Javadoc for the supplier variant needs to mention that an NPE is
> thrown if the supplier itself is null.
> @throws NullPointerException if {@code obj} is null and either {@code
> supplier} is null or the {@code supplier.get()} value is {@code null}


Shouldn’t the supplier variant signature be as follows:
  public static <T> T nonNullOf(T obj, Supplier<? extends T> supplier) {


More information about the core-libs-dev mailing list