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. --- Original message --- From: "Stuart Marks" <stuart.ma...@oracle.com> Date: 28 April 2016, 05:50:45 > > Is there a better way of doing this? We'd almost need a > > ifPresentElse(Consumer<? super T> consumer, Runnable action) method I guess. > Close. In JDK 9 we added > > ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction) > > s'marks