我们如何为 Realm 模型字段提供默认值?
示例:
class Demo extends RealmObject{
private String id; // I want to set this id to a uuid
private boolean isVisibile; // set this to default as true
}
最佳答案
class Demo extends RealmObject{
public Demo() {
id = UUID.randomUUID().toString();
isVisible = true;
}
@PrimaryKey
private String id; // I want to set this id to a uuid
private boolean isVisibile; // set this to default as true
}
应该在 Realm 2.0+ 上工作
关于java - 如何为 Realm 中的字段设置默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560155/