October 2019
Intermediate to advanced
434 pages
11h 54m
English
To create a data class, we can add the data keyword to a class declaration as long as the class follows several specific rules:
In this example, we define a data class, Article, which contains two primary constructor properties:
data class Article(val title: String, val author: String)
Primary constructor properties will be included in the generated implementations of copy(), equals(), hashCode(), and toString().
A data class may also contain properties that are not defined in the primary constructor:
data class Article(val title: String, val author: String) { var snippet: String = ""}
Data class properties ...
Read now
Unlock full access