为什么这个Java 8类型推断失败了?

时间:2016-01-05 13:45:34

标签: java java-8 type-inference

为什么以下代码

CompletionStage<Optional<String>> future = completedFuture(Optional.empty());
future.thenApply(optStr -> {
  return optStr.map(s -> s.length())
      .orElseThrow(() -> new IllegalArgumentException("Empty string"));
});

无法编译,

unreported exception X; must be caught or declared to be thrown

IllegalArgumentException的显式类型参数传递给orElseThrow

0 个答案:

没有答案