From the course: Android Development Tips

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Use Kotlin data and enum classes

Use Kotlin data and enum classes - Android Tutorial

From the course: Android Development Tips

Use Kotlin data and enum classes

- [Instructor] Kotlin gives you many ways of managing data in memory. Just like in Java, you can create classes designed to hold one instance of a particular type. In Kotlin, these are called Data Classes. And within those Data Classes, you can have properties representing values, and when a property can have one of a finite number of possible values, you can represent those values with something called an Enum class. I'll start in this demonstration by creating a new Kotlin class. And I'll put it in my base package. I'll select New Kotlin File or Class, and I'll call this Clothing Item. And I'll set its kind as Class, and I'll create it. Now, the clothing item is going to have a clothing type. I'll declare the various possible values for the clothing type using an Enum class. And I'll create this as a nested class within the Clothing Item class. I'll name this Clothing Type and I'll assign three possible values. These are kind of like constants, so I use upper case characters to…

Contents