-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
b36
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8193650 | 11 | Stuart Marks | P3 | Resolved | Fixed | team |
Optional.get() is an "attractive nuisance" and is too tempting for programmers, leading to frequent errors. People don't expect a getter to throw an exception. A replacement API for Optional.get() with equivalent semantics should be added. The specification for Optional.get() should direct readers to the new API. However, Optional.get() shouldn't be deprecated just yet; deprecation is covered by the follow-on issue JDK-8160606.
The current proposal for replacement is a no-arg Optional.orElseThrow(). This fits well within the family of or-else methods, and it's closely related to orElseThrow(exSupplier), as if providing a NoSuchElementException supplier as a default.
The current proposal for replacement is a no-arg Optional.orElseThrow(). This fits well within the family of or-else methods, and it's closely related to orElseThrow(exSupplier), as if providing a NoSuchElementException supplier as a default.
- backported by
-
JDK-8193650 (opt) add no-arg orElseThrow() as preferred alternative to get()
- Resolved
- csr for
-
JDK-8193280 (opt) add no-arg orElseThrow() as preferred alternative to get()
- Closed
- relates to
-
JDK-8160606 (opt) deprecate Optional.get()
- Open
-
JDK-8157055 consider unified release notes for deprecated APIs
- Closed
There are no Sub-Tasks for this issue.