Why does the following code,
CompletionStage<Optional<String>> future = completedFuture(Optional.empty());
future.thenApply(optStr -> {
return optStr.map(s -> s.length())
.orElseThrow(() -> new IllegalArgumentException("Empty string"));
});
fail to compile with,
unreported exception X; must be caught or declared to be thrown
Passing an explicit type argument of IllegalArgumentException
to orElseThrow
works.