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

标签 android constructor kotlin android-room

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

warning: There are multiple good constructors and Room will pick the no-arg constructor. You can use the @Ignore annotation to eliminate unwanted constructors.

自动生成类

public final class Gender {
             ^

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 = "")

最佳答案

我有同样的警告,我只是把 @Ignore 放在我的空构造函数之前

// Empty constructor
@Ignore
public Room_Database() {
}

关于android - 有多个好的构造函数,Room 会选择无参数构造函数。如何解决此警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52983393/

相关文章:

android - 在gradle android中获取重复资源错误

c++ - 虚拟继承与非默认构造函数

java - 为什么以数组为参数的构造函数在参数 [java] 中以 Object 为参数的构造函数之前?

android - Jetpack 撰写内部编译器参数警告

json - 使用Kotlinx.Serialization解析嵌套的JSON

android - Markdown 库不支持 android 中的单个\n

Android 强制关闭无法捕获无法报告

android - 在安卓 : How to define proper Animation to maximize one View while minimizing 2 others at the same time?

php - 将 MySQL 查询转换为对象的最佳方法

Android约束布局包括另一个布局