JDK 26 and JEP 500 introduce warnings when final fields are mutated via reflection, moving toward true immutability. The post covers common scenarios where final field mutation occurs — including platform serialization, custom serialization, dependency injection, and cloning — and provides concrete alternatives for each. Key recommendations include embracing constructor injection, using records as transparent data carriers, adopting the serialization proxy pattern, and avoiding the construct-first-assign-later approach. New command-line flags `--enable-final-field-mutation` and `--illegal-final-field-mutation` are introduced to manage legacy code during the transition.
Table of contents
Initializing InstancesPlatform SerializationSerializationDependency InjectionCloningNon-Construction CasesSort: