Search code examples
androidkotlindbflow

Unresolved reference KClass trying to use DBFlow and Kotlin with Android


I'm using kotlin 1.0.1-2 in my Android project. I want to use DBFlow as my ORM. But it demands the use of the Table annotation for my classes to be persisted. The Table annotation has the Database attribute. And this attribute expects a KClass. Nevertheless, the following code simply doesn't compile. The error says: Unresolved reference KClass. Whose fault is that? Thanks in advance.

import com.raizlabs.android.dbflow.annotation.Column
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import com.raizlabs.android.dbflow.structure.BaseModel
import java.util.*
import kotlin.reflect.KClass

@Table(name = "items", database = KClass<AppDatabase>)
class Item : BaseModel() {
    @PrimaryKey(autoincrement = true)
    @Column(name = "id")
    var id: Long = 0
    @Column(name = "updated_at")
    var updatedAt: Calendar = Calendar.getInstance()
}

Solution

  • Apparently I was not supposed to use KClass in that manner. The correct way in current Kotlin is AppDatabase::class instead of KClass<AppDatabase>.