在Kotlin中,可以使用Room的@ForeignKey作为@Entity参数。

14 浏览
0 Comments

在Kotlin中,可以使用Room的@ForeignKey作为@Entity参数。

我遇到了一个使用类定义上的@PrimaryKey注解的Room教程:tutorial

@Entity(foreignKeys = @ForeignKey(entity = User.class,
                              parentColumns = "id",
                              childColumns = "userId",
                              onDelete = CASCADE))
public class Repo {
    ...
}

现在,我有一个数据类,想要在其上使用一个主键:

@Parcel(Parcel.Serialization.BEAN)

data class Foo @ParcelConstructor constructor(var stringOne: String,

var stringTwo: String,

var stringThree: String): BaseFoo() {

...

}

因此,我也在顶部添加了@Entity(tableName = "Foo", foreignKeys = @ForeignKey(entity = Bar::class, parentColumns = "someCol", childColumns = "someOtherCol", onDelete = CASCADE))片段,但是我无法编译:

注解不能用作注解的参数。

我想知道:为什么(我认为是)相同的概念在Java中可以工作,但在Kotlin中却不行?此外,是否有办法解决这个问题?欢迎提供任何意见。

0