From the course: Kotlin Essential Training: Object-Oriented and Async Code
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Data classes - Kotlin Tutorial
From the course: Kotlin Essential Training: Object-Oriented and Async Code
Data classes
- [Instructor] When writing object oriented code, it's common practice to have types that are simple value holders, that have no real business, logic, or purpose other than to hold some set of data. Data classes in Kotlin are specifically designed for this purpose and have several useful traits that help reduce boilerplate code. We can define a data class, much like a regular class, but using the data modifier and with a few restrictions. So let's open up our Project pane here, and we're going to create a new Kotlin class or file, and we are going to select the Data class option, and we will name this class Task. So this is now created a new Task.kt file. And with it, a data class named Task. Notice the data modifier in front of the class name. This is what differentiates a class from a data class. Now, by adding that data modifier, we bring with it some restrictions that data classes have. And one of those special…
Contents
-
-
-
Classes19m 32s
-
(Locked)
Interfaces12m 29s
-
(Locked)
Enum classes12m 13s
-
(Locked)
Data classes11m 47s
-
(Locked)
Object classes7m 9s
-
(Locked)
Sealed classes11m 42s
-
(Locked)
Companion objects6m 45s
-
(Locked)
Challenge: Create a Result type using a sealed class1m 45s
-
(Locked)
Solution: Create a Result type using a sealed class6m 13s
-
-
-
-