JavaIntermediate#fundamentals#java14

What are records in Java (Java 14+)?

Records are immutable data carrier classes that automatically generate constructors, accessors, equals(), hashCode(), and toString() based on their declared components, reducing boilerplate for DTOs.

Example
record Point(int x, int y) {}
Point p = new Point(1, 2);
p.x(); // 1
System.out.println(p); // Point[x=1, y=2]

Related Questions

1
JavaAdvanced#fundamentals#java17

What is the difference between sealed classes and final classes (Java 17)?

Open
2
JavaIntermediate#fundamentals#java14

What is the difference between switch statement and switch expression (Java 14+)?

Open
3
JavaBeginner#strings#java15

What is text block syntax in Java (Java 15+)?

Open