Optional.orElse(null) ambiguity (original) (raw)

Tim Peierls tim at peierls.net
Mon Jan 14 10:55:41 PST 2013


On Mon, Jan 14, 2013 at 1:23 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

Null is a valid value for orElse(T) but not for orElse(Supplier). So we care about this ambiguity (there are other similar ones we don't care about, when null isn't a valid value for either option.)

Guava Optional has or(T), or(Supplier<? extends T>), and orNull() where null is not an acceptable argument value for either of the first two.

That has worked well for me in practice, but it would be hard on folks who insist on being able to stick null everywhere.

--tim



More information about the lambda-libs-spec-observers mailing list