1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-08-01 16:28:03 +08:00

Compare commits

..

No commits in common. "1ccf42faad30cb4488040938833301e502a2674d" and "31ae380b053f882213fba2689cd1d88a5553bd04" have entirely different histories.

View File

@ -81,11 +81,11 @@ list.stream().collect(Collectors.toUnmodifiableSet());
## Optional 增强
`Optional` 新增了一个无参的 `orElseThrow()` 方法,作为带参数的 `orElseThrow(Supplier<? extends X> exceptionSupplier)` 的简化版本,在没有值时默认抛出一个 NoSuchElementException 异常。
`Optional` 新增了`orElseThrow()`方法来在没有值时抛出指定的异常。
```java
Optional<String> optional = Optional.empty();
String result = optional.orElseThrow();
Optional.ofNullable(cache.getIfPresent(key))
.orElseThrow(() -> new PrestoException(NOT_FOUND, "Missing entry found for key: " + key));
```
## 应用程序类数据共享(扩展 CDS 功能)