new
或 getOrCreate
函数在 ChangeScope
中创建时 Entity
的未分配属性。
必须分配 Entity
的所有非可 null 属性,或者使用 @Many
注解对其进行标记。
否则,可能会导致运行时异常。
示例:
interface A: Entity {
var x: Int
var y: Int?
@Many var z: Int
var p: Int
}
fun ChangeScope.foo() {
new(A::class) {
this.p = 0
}
}
可以通过快速修复来为缺失的必需属性生成赋值
fun ChangeScope.foo() {
new(A::class) {
this.x = x
this.p = 0
}
}