Data classes

We are maintaining Polls and Poll, which is our model. For this purpose, we have data classes in Kotlin. All the pain that we used to endure to create and maintain POJO classes in Java is gone. No need to have those dedicated packages to hold your model class. Any Kotlin file can hold your data class. By default, it provides methods such as toString()equals(), and copy(), as well as the hashCode() method implementation. In Android, we mostly use these types of classes to hold our JSON responses in the form of model classes. You can check out the data classes we created in Models.kt.

Some points to consider when using data classes:

  • The primary constructor needs to have at least one parameter.
  • All primary constructor parameters ...

Get Hands-On Serverless Applications with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.