An OpenJDK proposal would present computed constants to Java. Immutable worth holders that are initialized at the majority of when, computed constants provide the efficiency and safety benefits of last fields while using more versatility as to the timing of initialization.The proposition is currently
have constraints. As a result, designers must pick between the benefits of finality and flexibility in timing of initialization. Developers have developed methods to ameliorate the imbalance, but none are ideal.The calculated constants API defines classes and a user interface so customer code in applications and libraries can perform jobs including defining and using computed continuous things and consistent collections. The API lives in the java.lang package of the java.base module.Goals of the strategy consist of: Decoupling initialization of computed constants from the initialization of their containing item or class. Providing an instinctive API for computed constants and collections. Allowing consistent
frozen, with the release due in September, the earliest possible version of basic Java that might consist of computed constants would be JDK 22, due in March 2024. Copyright © 2023 IDG Communications,
Inc. Source