
A JDK Enhancement Proposal (JEP) to prepare to make final mean final in Java would difficulty warnings about makes use of of deep reflection to mutate last fields. The warnings would put together Java builders for a future launch that ensures integrity by default by limiting last subject mutation, making Java safer and probably sooner.
The proposal was created in early-February and up to date on March 31. A key objective of the plan is to arrange the Java ecosystem for a future launch that by default disallows mutation of last fields by deep reflection. As of that launch, builders must explicitly allow the potential to mutate last fields at startup. Different objectives embody aligning last fields in regular lessons with parts of document lessons, which can’t be mutated by deep reflection, and permitting serialization libraries to proceed working with Serializable
lessons, even these with last fields. There is no such thing as a plan to deprecate or take away any a part of the Java Platform API or forestall mutation of ultimate fields by serialization libraries throughout deserialization. The JEP at present doesn’t listing a model of Java that might get the final-means-final functionality.
Detailing motivation for the plan, the proposal says Java builders depend on last fields to symbolize immutable state. The expectation {that a} last subject can’t be reassigned, whether or not intentionally or by chance, is commonly essential when builders cause about correctness. However the expectation {that a} last subject can’t be reassigned is fake. The Java platform offers APIs that enable reassignment of ultimate fields at any time by any code in this system, thus undermining reasoning about correctness and invalidating necessary optimizations. Thus a last subject is as mutable as a non-final subject.