Skip to content

Commit 1ccf42f

Browse files
authored
Merge pull request #2691 from x0c/x0c-patch-1
修正 Java 10 中的 Optional 增强描述
2 parents 31ae380 + a11786e commit 1ccf42f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/java/new-features/java10.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ list.stream().collect(Collectors.toUnmodifiableSet());
8181

8282
## Optional 增强
8383

84-
`Optional` 新增了`orElseThrow()`方法来在没有值时抛出指定的异常
84+
`Optional` 新增了一个无参的 `orElseThrow()` 方法,作为带参数的 `orElseThrow(Supplier<? extends X> exceptionSupplier)` 的简化版本,在没有值时默认抛出一个 NoSuchElementException 异常
8585

8686
```java
87-
Optional.ofNullable(cache.getIfPresent(key))
88-
.orElseThrow(() -> new PrestoException(NOT_FOUND, "Missing entry found for key: " + key));
87+
Optional<String> optional = Optional.empty();
88+
String result = optional.orElseThrow();
8989
```
9090

9191
## 应用程序类数据共享(扩展 CDS 功能)

0 commit comments

Comments
 (0)