I need a list<Object>
using Realm. I tried RealmList<RealmObject>
but it doesn't work because RealmObject
is abstract.
Asked
Active
Viewed 2.8k times
21

Mureinik
- 297,002
- 52
- 306
- 350

Bachlet Tansime
- 1,273
- 3
- 12
- 17
-
can you explain these lines : " I try RealmList but it dosen't work because RealmObject it's abstract ". – Abhinav Gauniyal May 07 '15 at 10:05
-
I need List – Bachlet Tansime May 07 '15 at 10:11
-
1I don't know Realm but RealmList> can solve your problem. – Muzaffer May 07 '15 at 10:20
-
How about `RealmList extends RealmObject>` ? – Emanuelez May 07 '15 at 10:24
-
Thank's, but it's working, because after I need to add object from model with index, it forced me to change ? to my object. – Bachlet Tansime May 07 '15 at 10:28
1 Answers
61
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

Héctor
- 24,444
- 35
- 132
- 243

Christian Melchior
- 19,978
- 5
- 62
- 53