Created
November 18, 2025 22:58
-
-
Save JosePaumard/648ca626258aae79e299f315ed03b717 to your computer and use it in GitHub Desktop.
How to observe the mutation of a final field before its initialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A { | |
| public A() { | |
| IO.println(message()); | |
| } | |
| public String message() { | |
| return "Hello World!"; | |
| } | |
| } | |
| class B extends A { | |
| private final String message; | |
| public B(String message) { | |
| this.message = message; | |
| } | |
| public String message() { | |
| return this.message; | |
| } | |
| } | |
| void main() { | |
| var b = new B("Bonjour le monde !"); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This problem is fixed by adding an explicit call to super() on line 14, after the initialization of message (Java 25 and later).