List<Object> Or RealmList on Realm Android

前端 未结 1 1656
旧时难觅i
旧时难觅i 2021-01-07 22:47

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

1条回答
  •  星月不相逢
    2021-01-07 23:29

    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 objects;  // not legal
      private RealmList objects;  // not legal 
      private RealmList objects; // not legal
    }
    
    public class Foo extends RealmObject {
      private RealmList objects; // legal
    }
    
    List reference = foo.getObjects(); // Legal
    
        

    0 讨论(0)
    提交回复
    热议问题