gpt4 book ai didi

java - 实现 RealmModel 而不是在 Realm 中扩展 RealmObject 有什么好处吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:07:35 25 4
gpt4 key购买 nike

Realm 中,为了使对象能够持久化,它必须实现 RealmModel 或扩展 RealmObject。使用一个比另一个有好处吗?

realm docs 中的所有内容是:

An alternative to extending the RealmObject base class is implementing the RealmModel interface and adding the @RealmClass annotation.

All methods available on RealmObject are then available through static methods.

最佳答案

考虑到 extending any non-RealmObject classes is not possible even if you're implementing RealmModel and adding @RealmClass ,在我看来,你只是通过强制自己使用例如 RealmObject.isValid(realmObject) 而不是你自然免费使用的 realmObject.isValid() 来获得额外的复杂性扩展 RealmObject

所以不,你应该坚持扩展 RealmObject。使用 implements RealmModel 不会给您带来额外的好处。

关于java - 实现 RealmModel 而不是在 Realm 中扩展 RealmObject 有什么好处吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39519901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com