According to the Java VM Specification, final fields can be modified by the `putfield` byte code instruction only if the instruction appears in the instance initializer method `<init>` of the field's declaring class. Similar, static final fields can be modified by a `putstatic` instruction only if the instruction appears in the class initializer method `<clinit>` of the field's declaring class. With the JDK 9 release, the HotSpot VM fully enforces the previously mentioned restrictions, but only for class files with version number >= 53. For class files with version numbers < 53, restrictions are only partially enforced (as it is done by releases preceding JDK 9). That is, for class files with version number < 53, final fields can be modified in any method of the class declaring the field (not only class/instance initializers).
|