【问题标题】:Unresolved reference KClass trying to use DBFlow and Kotlin with Android未解决的参考 KClass 试图在 Android 中使用 DBFlow 和 Kotlin
【发布时间】:2016-05-06 01:38:55
【问题描述】:

我在我的 Android 项目中使用 kotlin 1.0.1-2。我想使用 DBFlow 作为我的 ORM。但它需要使用 Table 注释来持久化我的类。 Table 注释具有 Database 属性。这个属性需要一个 KClass。然而,下面的代码根本无法编译。错误显示:Unresolved reference KClass。那是谁的错?提前致谢。

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()
}

【问题讨论】:

    标签: android kotlin dbflow


    【解决方案1】:

    显然我不应该以这种方式使用 KClass。当前 Kotlin 中的正确方法是 AppDatabase::class 而不是 KClass&lt;AppDatabase&gt;

    【讨论】:

      猜你喜欢
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      • 2019-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多