当我在Java中使用@Database
定义Room的数据库时:
@Database(entities = {JustSomeEntity.class}, version = 1)
当我在 Kotlin 中使用 @Database
定义 Room 的数据库时:
@Database(entities = arrayOf(JustSomeEntity::class), version = 1)
请注意 Kotlin 版本中的 arrayOf
。
参见official docs for reference - 您可以在那里切换 Java/Kotlin 并查看。
这是某种 Java/Kotlin/注释怪癖吗?这是为什么?它从哪里来?
最佳答案
在 Java 中,花括号定义一个值数组。请参阅文档:
Alternatively, you can use the shortcut syntax to create and initialize an array:
int[] anArray = {
100, 200, 300,
400, 500, 600,
700, 800, 900, 1000
};
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
关于java - 为什么在 Kotlin 中 Room 的 @Database 获取实体为 arrayOf,而 Java 不获取数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61182906/