现代 Java 代码片段集合。每个旧 Java 模式与其简洁的现代替代方案并排展示。
public class Point {
private final int x, y;
public Point(int x, int y) { ... }
public int getX() { return x; }
public int getY() { return y; }
// equals, hashCode, toString
}
public record Point(int x, int y) {}