News for hackers. Stuff that matters.
Re:Show HN: I Wrote a Book on Java by vips7L on Monday September 23, 2024 @04:06PM (#41629926)
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);
        }
    }
Re:Show HN: I Wrote a Book on Java by nogridbag on Tuesday September 24, 2024 @03:41PM (#41640134)
I think records will be much more useful if https://openjdk.org/jeps/468 gets out of preview.