Flexible constructor bodies
Validate and compute values before calling super() or this().
Code Comparison
✕ Java 8
class Square extends Shape {
Square(double side) {
super(side, side);
// can't validate BEFORE super!
if (side <= 0)
throw new IAE("bad");
}
}
✓ Java 25+
class Square extends Shape {
Square(double side) {
if (side <= 0)
throw new IAE("bad");
super(side, side);
}
}
Why the modern way wins
Fail fast
Validate arguments before the superclass constructor runs.
Compute first
Derive values and prepare data before calling super().
No workarounds
No more static helper methods or factory patterns to work around the restriction.
Old Approach
Validate After super()
Modern Approach
Code Before super()
Since JDK
25
Difficulty
intermediate
JDK Support
Flexible constructor bodies
Available
Finalized in JDK 25 LTS (JEP 513, Sept 2025).
How it works
Java 25 lifts the restriction that super() must be the first statement. You can now validate arguments, compute derived values, and set up state before delegating to the parent constructor.