Android 错误:字段的getter不明确,您可以@忽略您没有的getter';我不想比赛
我有以下代码结构:Android 错误:字段的getter不明确,您可以@忽略您没有的getter';我不想比赛,android,kotlin,android-room,Android,Kotlin,Android Room,我有以下代码结构: interface Watchable { fun show: Show } @Entity @Parcelize data class TopRatedShow( @Embedded val show: Show, @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "topRatedShowId") val id: Int = show.id ) : Par
interface Watchable {
fun show: Show
}
@Entity
@Parcelize
data class TopRatedShow(
@Embedded
val show: Show,
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "topRatedShowId") val id: Int = show.id
) : Parcelable, Watchable {
override fun show(): Show {
return show
}
}
但我的代码不会编译并抛出:
error: Ambiguous getter for Field(element=show, name=show, type=com.zk.***.Show,
affinity=null, collate=null, columnName=show, defaultValue=null, parent=null,
indexed=false, nonNull=true).
All of the following match: show, getShow.
You can @Ignore the ones that you don't want to match.
private final com.zk.***.Show show = null;
似乎是@Embedded与实现接口相结合导致了问题,但我不完全理解问题出在哪里因为所有的类、函数签名以及val名称都显示出来了,所以房间在选择哪一个方面存在问题
interface Watchable {
fun show: Show
}
@Entity
@Parcelize
data class TopRatedShow(
@Embedded
val myshow: Show,
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "topRatedShowId") val id: Int = myshow.id
) : Parcelable, Watchable {
override fun show(): Show {
return myshow
}
}
您可以更改val名称,也可以使用@ignore告诉房间忽略哪一个,是的,就是这样,谢谢!