Grokking Java Interview Questions
0% completed
Records
A class for one line of an order has two final fields, a constructor, two methods that return the fields, and its own equals(), hashCode(), and toString(). Written as an ordinary class, it took 36 lines in our version. Written as a record, it takes one: record Item(String product, int quantity) { }.
The two versions do the same work, but the short one accepts fewer changes. It cannot receive a setter that changes the object, an additional instance field, or another parent class
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%