Optional.orElse(null) ambiguity

Joe Bowbeer joe.bowbeer at gmail.com
Sun Jan 13 22:00:23 PST 2013


In b72, optional.orElse(null) is ambiguous because it matches both of the
orElse forms:

  T orElse(T other)
  T orElse(Supplier<T> other)

For example, this won't compile:

  return stream.max(comparator).orElse(null);


Optional needs a concise way to return null, so I suggest:

  T orElseNull()

--Joe


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