From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

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

Data classes

Data classes

- [Instructor] Now, that is almost the basics of classes covered. Although we've managed to remove a lot of Java's boilerplate code by creating the classes in this way, we still have had to write the toString method. We probably should have done a hashcode and an equals. So there's still some boilerplate required. I think, in fact, let's work now on that top version up here. This class, this Customer class up here. So here we've got constructors, we've got the equivalents of gets and sets created for it. But if I was going to do a good job on this Customer class, I'd still want to create a hashcode and an equals. So because of that, Kotlin gives us an alternative way to create a class which is useful specifically when the class is designed to store data. And that is, we put the keyword data in front of the keyword class. So I'm going to change Customer from a class to a data class. That's the only change I need to make. And the difference, by putting that keyword data in, is it now…

Contents