Return to site

☕ Java 26 — JEP 500: Prepare to make final mean final

· java
class C {
 final int x;
 C() {x = 100;}
}
static void main() throws NoSuchFieldException,
 IllegalAccessException {
 var f = C.class.getDeclaredField( "x" );
 f.setAccessible( true );
 var obj = new JEP500().new C();
 IO.println( obj.x );
 f.set( obj, 200 );
 IO.println( obj.x );
 /*output:
 100
 200
 WARNING: Final field x in class com.vv.JEP500$C has been mutated ...
 WARNING: Use --enable-final-field-mutation=ALL-UNNAMED ...
 WARNING: Mutating final fields will be blocked in a future release ....
 */
}

• JDK 26 starts warning about deep reflection that mutates final fields.

• This prepares the ecosystem for a future release where such mutation is denied by default.

• For developers, the action item is simple: run tests, find reflection-heavy libraries, and see who still breaks final.

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaBook👇