, IDEA , , , , b.isPresent() a.orElseGet(...).
, , IDE -, (), , , , .
Optional, isPresent api . (), .
, :
final Optional<String> a = Optional.of("1");
final Optional<String> b = Optional.empty();
Integer result = a
.map(s -> s + "0")
.map(Integer::parseInt)
.orElseGet(() -> b.map(Integer::parseInt).orElse(0));
System.out.println(result);
, , IllegalStateException :
final Optional<String> a = Optional.of("1");
final Optional<String> b = Optional.empty();
Integer result = a
.map(s -> s + "0")
.map(Integer::parseInt)
.orElseGet(() -> b.map(Integer::parseInt).orElseThrow(IllegalStateException::new));
System.out.println(result);