J.IX · Java 25 practice question
Which explicit constructor invocation rule applies to a non-canonical constructor of a record class in Java 25?
Check answer and explanation
Correct answer: It must contain an alternate constructor invocation this(...) and not super(...)
Explanation
A non-canonical record constructor must delegate via an alternate constructor invocation this(...) and must not contain a superclass constructor invocation super(...).
Common trap
Records implicitly extend java.lang.Record and do not allow constructors to invoke super(...) directly. Forbidding explicit constructor invocations applies to canonical record constructors, not non-canonical ones.
Source: JEP 513: Flexible Constructor Bodies — Description
Checked against the cited text on 2026-11-25.