RFR(m): 8140281 deprecate Optional.get()
stuart.marks at oracle.com
Thu Apr 28 23:41:48 UTC 2016
On 4/28/16 2:26 AM, Victor Polischuk wrote:
> I am sorry if my comment would be inappropriate, but is there a reason not to
> introduce "Optional<T> ifAbsent(Runnable emptyAction)" and change signature
> of ifPresent to "Optional<T> ifPresent(Consumer<? super T> consumer)"?
> In that case method chaining would be more natural and it will give a decent
> way to have more than one simple action assigned to Optional without creating
> messy java block.
Yes, this is starting to veer off topic from Optional.get().
I'll just say that a few methods have been added to Optional in Java 9:
ifPresentOrElse(), or(), and stream(). It seems pretty complete now. Please see
the Java 9 early access docs for details:
More information about the core-libs-dev