I have a Room database that contains Stuff entities. These entities have an ID that will be auto-generated:
@Entity(tableName = "stuff")
data class Stuff(val text: String) {
@PrimaryKey(autoGenerate = true) var id: Int = 0
}
There are two things I don't like with my code:
- I am initializing the id with 0, even though it should be initialized by Room.
- The id data member is mutable.
I tried using lateinit var but the compiler wouldn't let me do it on a primitive type. Is there a way to overcome the two issues mentioned above in Kotlin?