Summary
This API was first previewed in JDK 25 via JEP 502: Stable Values and then in JDK 26 via JEP 526 Lazy Constants. Based on experience and feedback, we propose to remove two methods from LazyConstant and add support for lazy sets.
Problem
The methods LazyConstant::isInitialized and LazyConstant::orElse could result in usages that were outside the design goals of the Lazy Constant API.
There was support for lazy lists and maps, but not for lazy sets. Some corner cases, such as TOC-TOU protection and the use of exotic Set equality schemes, were not specified.
The concept of an-ever-retrying computing function was abandoned, and now, a true at-most-once invocation is desired instead.
Solution
-
Remove the
LazyConstant::isInitializedandLazyConstant::orElsemethods. -
Add a new factory method
Set::ofLazythat allows the creation of lazy sets. -
Add additional verbiage around
Map::ofLazyandSet::ofLazymethod requirements on the provided Set specifying key/membership candidates. -
Make
LazyConstantand the lazy collections transition to an error state upon detecting that the computing function throws, and update the docs accordingly.
Specification
See attachment.
- csr of
-
JDK-8376811 Implement JEP 8376595: Lazy Constants (Third Preview)
-
- New
-