Chapter 9. Data Classes
We came across the term data class in Chapter 3, Object Oriented Programming in Kotlin ; however, we didn't go into much detail of what it could bring to the table. This chapter will cover the process of annotating classes, which will allow you to have boilerplate-free code. We will dig deep to see what the compiler does for us behind the scenes when we use a data class. In this chapter, you will learn:
- What destructuring is and how data classes are automatically eligible for destructuring operations
- How you get copy, toString, hashCode, and equals methods implemented for you
- Rules to obey when defining data classes
- Limitations of data classes
Data classes are intended for types that are meant to be data containers and nothing more. Code readability is important to me and most likely to anyone who reads this book. When you open a source file, you would really want to be able to quickly grasp what the code does. When it comes to a POJO (Plain O ld...