Record patterns bind a record's components directly in instanceof or switch.
record Point(int x, int y) {}
Object o = new Point(3, 4);
if (o instanceof Point(int x, int y)) {
System.out.println("x+y = " + (x + y));
}
x+y = 7
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