×
ラムダ式と関数型インターフェース
従来のデータ保持クラスと、レコードクラスの定義・使用例の比較コード例です。
// レコードクラスの定義 (これだけで全自動生成される!)
public record Point(int x, int y) {}

public class RecordExample {
    public static void main(String[] args) {
        Point p = new Point(10, 20); // 自動生成された正規コンストラクタ

        // 自動生成されたアクセサメソッド (getX() ではなく component名と同名)
        System.out.println(p.x()); // 10
        System.out.println(p.y()); // 20

        System.out.println(p); // 自動生成された toString -> Point[x=10, y=20]
    }
}

もう少し詳しく