Flexible Constructor Bodies in Java: Phases

JDK 24 delivers the third preview of the Flexible Constructor Bodies feature via JEP 492. It introduces the concept of constructor phases:
-
The prologue runs before the explicit constructor invocation.
-
The epilogue runs after the explicit constructor invocation.
To illustrate, the following Java program:
void main() { new CC();}class CC extends C { CC() { IO.println("CC prologue"); this(true); IO.println("CC epilogue"); } private CC(boolean internal) { IO.println("CX prologue"); super(); IO.println("CX epilogue"); }}class C { C() { IO.println(" C prologue"); super(); IO.println(" C epilogue"); }}
Prints:
CC prologue
CX prologue
C prologue
C epilogue
CX epilogue
CC epilogue