有多个好的构造函数,Room 会选择无参数构造函数。如何解决这个警告

Kis*_*nga 9 android constructor kotlin android-room

我尝试Room Persistent Database在 android kotlin 项目中实现库,但在编译时捕获此警告。我不知道如何解决这场战争。

警告:有多个好的构造函数,Room 将选择无参数构造函数。您可以使用@Ignore注释来消除不需要的构造函数。

自动生成的类

public final class Gender {
             ^
Run Code Online (Sandbox Code Playgroud)

Kotlin 数据类

import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey

@Entity
data class Gender(@PrimaryKey(autoGenerate = true)
             var genderId: Int = 0,
             var type: String = "")
Run Code Online (Sandbox Code Playgroud)

Er1*_*Er1 3

尝试这个:

import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey

@Entity
class Gender @Ignore constructor(@PrimaryKey(autoGenerate = true)
             var genderId: Int = 0,
             var type: String = "") {

    constructor() : this(0, "")
}
Run Code Online (Sandbox Code Playgroud)

就像警告说的那样

(...) Room 将选择无参数构造函数。(...)

您的构造函数确实有两个参数。您需要添加一个空的并忽略另一个