I'm new to the Java optionals but I see this code written by another developer and I don't get it:
String t = null;
Optional.ofNullable("notnull")
.orElse(
Optional.ofNullable(t).orElseThrow(() -> new Exception("MyException"))
);
Why does this code throw the exception? Why does it even go to the "orElse" branch?
Is this because of some weird execution order? So the first optional's value is not set before the orElse branch is evaluated?