- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 Realm 的新手,我想坚持以下模型:
public class ChangeEntry {
private int id;
private long time;
private boolean active;
private Set<Change> changes;
// getters and setters
}
Change
是一个 interface
(我有多个实现):
public interface Change {
void performChange();
}
据我所知,Realm 不支持 Set
,所以我进行了以下更改:
Set<Change>
切换至 RealmList<Change>
ChangeEntry
扩展 RealmObject
Change
扩展 RealmModel
现在当我尝试保存 ChangeEntry
到 Realm,我收到以下错误:
Only concrete Realm classes are allowed in RealmLists. Neither interfaces nor abstract classes are allowed.
这是不言自明的。
是否可以将此模型保存到 Realm 并保留 Change
的多态性接口(interface)提供?如果是,怎么办?
提前致谢。
最佳答案
Is it possible to save this model to Realm and preserve the polymorphism that the Change interface provides?
目前不支持,因为 realm 还不支持多态性。它正在处理中,您可以跟踪进度 here .
现在您只能使用具体类。
关于java - 如何将此模型转换为有效的 RealmObject?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46111527/
我遇到了 Realm 问题,每次我尝试在存储 RealmObject 后将其设置为另一个 RealmObject 时,都会导致它崩溃并出现 NullPointerException。 例如。
我想从它的 Realm 中“分离”一个 RealmObject,这意味着我希望能够从一个方法中返回一个 RealmObject并能够在我关闭 Realm 实例后使用它。 像这样: public Per
直接上代码。我们有两个类: class Rocket extends RealmObject { @PrimaryKey private long id; private String name
写入 Realm : Realm realm = Realm.getInstance(mContext); realm.beginTransaction(); InfoCocktail content
考虑以下 RealmObject 子类 public class TimeSlot extends RealmObject { @PrimaryKey private int value = 0;
假设我的 Realm 数据库中有三个对象/元素:- 一个 B C 当我使用方法deleteFromRealm() 删除第一个元素(即 A)时,剩余两个对象的位置会像这样改变:- C B 而不是:- B
我有一个 RealmObject User 存储在一个单例中并在整个应用程序中访问——它是在 UI 线程上检索的。该对象表示已登录的用户,与 Item 类具有一对多关系。在事务中更改它时,例如: Re
我是 Realm 的新手,我想坚持以下模型: public class ChangeEntry { private int id; private long time; pri
我试图从官方文档的“通知”部分了解 Realm 中的通知类型,当我在多个托管对象中使用 RealmObject addChangeListener 时,只有一个对象发生变化时,所有这些通知类型都会被调
我的应用从 REST API 获取数据。 根据端点,我得到完整或部分 Account 的列表。 当 API 响应时,我调用 realm.copyToRealmOrUpdate(accounts)。 我
我在我的项目中做 Realm 数据库。当您使用 Realm 时,您需要将简单对象扩展为 RealmObject。我有一个问题:如何在不扩展 RealmObject 的情况下创建对象,但我也使用 Rea
我的 Android 应用程序中有一个配置类,我将其存储在 Realm 数据库中。我只是对其进行了编辑以遵循单例设计模式,因此只有一次配置实例。 问题是,该类现在有一个私有(private)构造函数,
为什么这段代码会触发 java.lang.IllegalArgumentException: RealmObject 无效,因此无法复制 错误? realm.beginTransaction(); r
documentation对于 realmObject.isValid() 说: isValid() Checks if the realmObject is still valid to use i
我在我的 android 应用程序中使用 Realm 作为数据模块,尽管我遇到了一些关于如何将自定义方法分配给 Realm 对象的问题。在 iOS 核心数据模块中,您有 NSObjects,它们保存到
在我的应用程序中,我有以下 RealmObjects: 产品 - 这作为主数据,不应修改。 购物车 - 购物车允许人们挑选要购买的东西。内容将是选择类型。 选择 - 表示用户选择的产品以及颜色、尺寸等
我在 Android 上使用 Realm,我有一个需要序列化为 JSON 的 RealmObject,我正在使用 GSON。模型看起来像: @RealmClass public class User
我是 Android 版 Realm 的新手,所以我不确定我是否以正确的方式处理这个问题。我有一个看起来像这样的类: public class Entry extends RealmObject im
我们有一个简单的类Person,它继承自 Realm Object。现在我们希望该子类符合 Equatable 协议(protocol)。非常简单的代码如下所示。 class Person: Obje
假设异步API调用返回Member Data,它是一个RealmObject,并且Member被保存到realm中。 public class Member extends RealmObject {
我是一名优秀的程序员,十分优秀!