Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a11786e

Browse files
authored
修正 Java 10 中的 Optional 增强
1 parent 31ae380 commit a11786e

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(() ->newPrestoException(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)

AltStyle によって変換されたページ (->オリジナル) /