RFR 9: 8138963 : java.lang.Objects new method to default to non-null (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Fri Oct 9 07:59:22 UTC 2015


On 9 Oct 2015, at 02:31, John Rose <john.r.rose at oracle.com> wrote:

It may be instructive to link nulls to Optionals by encoding null-ness using Optional: T nonNullElse(T x, T y) := Optional.ofNullable(x).orElseGet(() -> Optional.ofNullable(y).get())

And with the new Optional.or [*] to be added soon the above could be expressed as:

:= Optional.ofNullable(x).or(() -> Optional.ofNullable(y))

Paul.

[*] i am searching for a better name, but don’t want to derail this thread with such a discussion.

T nonNullElseGet(T x, Supplier y) := Optional.ofNullable(x).orElseGet(() -> Optional.ofNullable(y.get()).get())



More information about the core-libs-dev mailing list