4 ms·
You can enforce some invariants during construction: record Point(int x, int y) { Point { if (x < 0) throw new IllegalArgumentException
by vips7L 2y ago
You can enforce some invariants during construction:
record Point(int x, int y) {
Point {
if (x < 0) throw new IllegalArgumentException()
}
}
or if you want to assert something is not null:
record Person(String name) {
Person {
requireNonNull(name);
}
}
- nogridbag 2y agoI think records will be much more useful if https://openjdk.org/jeps/468 https://openjdk.org/jeps/468 gets out of preview.