Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

compact constructor

A record constructor written with no parameter list, used to check and tidy the values before they are stored.

A compact constructor is a canonical constructor declared without a parameter list; its body runs on the implicit parameters, which it may reassign, and the fields are assigned from them when the body completes.

Examples

  • record Range(int low, int high) { Range { if (low > high) throw new IllegalArgumentException(); } }

Read the full section →