我有一个字段是Double
. 我想将其更改为double
字段。这是我为此设置的代码:
schema.get("Item")
.addField("mOriginalWeightUnboxed",double.class)
.transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
Double boxedWeight=obj.get("mOriginalWeight");
if (boxedWeight==null)
boxedWeight=0.0;
obj.setDouble("mOriginalWeightUnboxed",boxedWeight.doubleValue());
}
})
.removeField("mOriginalWeight")
.renameField("mOriginalWeightUnboxed","mOriginalWeight");
这是推荐的方法吗?