J.IX · Java 25 practice question
What happens when a developer compiles this Java 25 record?
public record Point(int x, int y) {
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
public static void main(String[] args) {
System.out.println(new Point(1, 2));
}
}
Check answer and explanation
Correct answer: Compilation fails because a canonical record constructor must not contain an explicit constructor invocation
Explanation
Even with flexible constructor bodies in Java 25, canonical record constructors remain restricted and must not contain an explicit constructor invocation such as super().
Common trap
Normal classes allow explicit super() calls, which tempts developers to assume canonical record constructors do too. Moving super() after field assignments would still fail because canonical record constructors forbid any explicit constructor invocation.
Source: JEP 513: Flexible Constructor Bodies — Description
Checked against the cited text on 2026-11-25.