Data Classes

Kotlin tries to eliminate repetition wherever it can.

The class mechanism performs a fair amount of work for you. However, creating classes that primarily hold data still requires a significant amount of repetitive code. When you need a class that’s essentially a data holder, data classes simplify your code and perform common tasks. You define a data class using the data keyword, which tells the compiler to generate additional functionality. Each constructor argument must be preceded by var or val:

End of sample. See for full early-access book.

Previous          Next

©2018 Mindview LLC. All Rights Reserved.