I think I'm starting to understand your question. The execution order with Optionalmay differ from what we are used to in procedural programming (the same is true for Java threads and other code using lambdas).
I will use two examples from the Eugenes answer :
o1.orElse(new MyObject());
Java: orElse() new MyObject() . , MyObject. orElse(). orElse() , Optional; ( ); , , . .
o1.orElseGet(() -> {
System.out.println("Should I see this");
return new MyObject();
});
, . . { } ( Should I see this Eugenes). orElseGet , Optional. , , , , . , , { } , , orElseGet().
, a MyObject . a Supplier . , , - . , . MyObject , , , , . Eugene , . , , , - .