If a is Optional[123] and b is Optional[empty].
a.orElse(b.orElseThrow(() -> new UnexpectedInternalException(
"Error")))
Why does it throw?
orElse() is a method, and before that method is executed, its arguments are evaluated. In this case the evaluation of the argument (b.orElseThrow(() -> new UnexpectedInternalException("Error"))) throws an exception.
Because parameters are evaluated first. This has nothing to do with Optional...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With