Record Patterns
Destructure records in patterns.
Record Patterns
A record pattern matches a record and destructures it, binding its components to variables in one step. No more calling each accessor by hand.
A Record to Destructure
Start with a simple record. Its components are what a pattern can extract.
public class Main {
record Point(int x, int y) {}
public static void main(String[] args) {
Point p = new Point(3, 4);
System.out.println(p.x() + ", " + p.y());
}
}