import java.util.Optional; class Test { public static void main(String[] args) { Optional> eith = Optional.of(new Either()); eith.map(either -> { String foo = Test.foo(either); return foo; }).orElse("Hello"); eith.map(either -> { return Test.foo(either); }).orElse("Hello"); eith.map(either -> Test.foo(either)).orElse("Hello"); } private static A foo(Either either) throws X { return null; } } class Either { }