Post

HN
Hacker News

JEP 539: Strict Field Initialization in the JVM moved to preview

Introduce strictly-initialized fields in the Java Virtual Machine. Such fields must be initialized before they are read, thus default values such as 0 or null are never observed. For strictly-initialized fields that are final, the same value is always observed. This is a preview VM feature , available for use by compilers that emit class files.

Offer designers of JVM-based programming languages a model for field initialization which has stronger integrity guarantees than the present model.

Give these designers the flexibility to choose, for each static and instance field in a class, whether to opt in to the new model or continue with the present model.

It is not a goal to introduce new Java language features, such as a strictly-initialized modifier for fields.

It is not a goal to change javac compilation strategies in order to impose strict field initialization on existing Java source code.

The Java Platform specifies that every variable is initialized before use, ensuring that a program can never read from uninitialized memory. If a field in a class — whether a static field or an instance field — is not initialized explicitly then it is initialized implicitly before it is used, by being set to a default value . This value is always some form of zero: the number 0, the boolean false , or a null reference.