JDK 26 introduces LazyConstants (JEP 526), a preview feature that provides a type-safe API for lazy initialization with constant-folding optimization guarantees. The new `LazyConstant<T>` type lets developers declare a final field with a supplier-based recipe, computing the value at most once on first access, even under concurrent conditions. Unlike typical lazy initialization patterns, `LazyConstant` leverages the `@Stable` annotation to signal to the JVM that the value will never change, enabling constant-folding optimizations. JEP 526 also introduces `List.ofLazy` and `Map.ofLazy` factory methods for lazy collections. The feature evolved from internal JVM stable variables, through the StableValue API in JDK 25, to the more user-friendly LazyConstants in JDK 26, with further API simplification planned for JDK 27.
Sort: