A record is a special kind of class designed to carry immutable data. The declaration record Point(int x, int y) {} lists the components in its header, and from that the compiler generates a private final field for each component, a canonical constructor taking all components in order, an accessor method for each component named exactly like it (x() and y(), not getX()), and implementations of equals, hashCode and toString based on all components.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 6 more sections, 4 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.