Skip to content

Support Java 16 compact canonical constructors for records #216

@marek-parfianowicz

Description

@marek-parfianowicz

When defining a record class, it's allowed to declare its constructor using a shorter syntax, without parameter list for a constructor.

Example from https://docs.oracle.com/javase/specs/jls/se17/html/jls-8.html#jls-8.10.4.2

record Rational(int num, int denom) {
private static int gcd(int a, int b) {
if (b == 0) return Math.abs(a);
else return gcd(b, a % b);
}

Rational {
int gcd = gcd(num, denom);
num /= gcd;
denom /= gcd;
}
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions