A record auto-generates constructor, accessors, equals, hashCode and toString.
record Point(int x, int y) {}
Point p = new Point(3, 4);
System.out.println(p);
System.out.println("x=" + p.x() + " y=" + p.y());
System.out.println(p.equals(new Point(3, 4)));
Point[x=3, y=4]
x=3 y=4
true
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-26