List<Object> Or RealmList<RealmObject> on Realm Android

旧时模样 提交于 2019-11-30 21:57:09

问题


I need a list<Object> using Realm. I tried RealmList<RealmObject> but it doesn't work because RealmObject is abstract.


回答1:


Christian from Realm here. You can only save objects that extend RealmObject inside a Realm. This is because Realm is not a schemaless database. We do require a schema and that schema is defined by your objects that extend RealmObject. We use RealmList because it abstracts away the communication with the underlying core database, but it implements the List interface.

This means that

public class Foo extends RealmObject {
  private List<Object> objects;  // not legal
  private RealmList<Object> objects;  // not legal 
  private RealmList<RealmObject> objects; // not legal
}

public class Foo extends RealmObject {
  private RealmList<Foo> objects; // legal
}

List<Foo> reference = foo.getObjects(); // Legal


来源:https://stackoverflow.com/questions/30097810/listobject-or-realmlistrealmobject-on-realm-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!