考虑到以下初始模型,一切似乎都可以在Room中正常工作:
interface ParentModel {
val name: String
val age: Int
}
@Entity(tableName = "parents")
open class ParentRoom(
@PrimaryKey override var name: String,
override var age: Int)
: ParentModel
但是,我不想使用接口,我希望它是
真实的
open class ParentModel(open val name: String, open val age: Int)
@Entity(tableName = "parents")
open class ParentRoom(
@PrimaryKey override var name: String,
override var age: Int)
: ParentModel(name, age)
不幸的是Room不会编译这个,因为它认为有两个列同名:
ParentRoom.java:7: error: Multiple fields have the same columnName: name. Field names: name, name.
public class ParentRoom extends ParentModel {
^
e: ParentRoom.java:10: error: Field has non-unique column name.
private java.lang.String name;
我想重写这些字段的原因是,这是对它们进行注释的唯一方法。这到底是可能的,还是我被迫使用与房间的接口?