From the course: Android Development Tips

Unlock this course with a free trial

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

Create Room entity classes in Kotlin

Create Room entity classes in Kotlin - Android Tutorial

From the course: Android Development Tips

Create Room entity classes in Kotlin

- [Instructor] Android Studio 3 includes complete support for programming with Kotlin. I've described how to create simple classes in Kotlin in previous tips. Now I'll show you how to create entity classes for the Room persistence library in Kotlin. In the database definition for this application, my Entity class for the notes table is declared in this Java class. The name of the class is Note. And it has an Entity annotation that sets the table name as notes. It has three fields that represent the columns in the table: an integer named noteId, that's the primary key, a noteDate value, and a string value. There's a no arguments constructor method that's required by Room, a constructor method I can use to create a new instance of the class easily, getters and setters for each of the fields, and a custom ToString method for debugging. Now I'm going to create a Kotlin version of that class. I'll go to my model package and create a new Kotlin file or class. I'll name it NoteKt, for…

Contents