From the course: Java SE 17 Developer (1Z0-829) Cert Prep

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Features of records

Features of records

- So a record type can actually have custom and customized methods. The automatic methods can be replaced. That's what I mean by customized. So we can take equals, hashCode and toString and also the access methods and redefine them if we choose. The replacement method we provide must conform to the expected signature. It can use an override annotation, but actually it isn't really an override, it's a replacement because there will be no super-dot method available to us, so we have to start again from scratch. We can also add custom methods. We can add additional methods of our own. These can be instance or static depending on how we feel about it. We're not allowed to have native or abstract methods. A record type, however cannot declare instance fields. Neither can it declare instance initializers. The auto-generated fields will exactly match the components, but a record can declare static fields and static initializers. These actually don't have to be final. They're not considered…

Contents