by wtetzner · 5y ago · 0 comments
For example:
public class Point {
private final x;
private final y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
I don't think this level of verbosity helps readability (at least not for anyone familiar with the language). Luckily, there's Lombok (and I think a recent or upcoming Java version is adding support for record syntax): @lombok.Value
public class Point {
int x;
int y;
} record Point(int x, int y) { }
No lombok needed. That is the same code, but it also has equals and hashCode methods.Boilerplate obfuscates.
The point is that I wanted statically typed records, which a dynamic language won't give me. Java has added syntax for defining records now, which is great, but I'm not (yet) able to use the latest version.
> makes your object’s serialization capabilities a dice roll
Not sure how? The effect of @Value is documented.
record Point(int x, int y) {}
[1] https://blogs.oracle.com/javamagazine/records-come-to-java
https://openjdk.java.net/jeps/395
Java 16 was only released within the last few weeks! (Gradle still has some trouble compiling it or running on it; Gradle 7 should be dropping soon with explicit Java 16 support.)