java – Realm and inheritance


I need to store information on certain classes, which, in turn, are inherited from other classes.

As far as I know, in 2015 the Realm developers wrote that inheritance is not yet supported, but its support is planned in the future.

Found information from mid-2016, which says that inheritance is not yet supported.

On the current version of Realm, I can't save inherited objects, but maybe I'm just doing something wrong?

Can you please tell me how Realm is doing with inheritance now?

If there is still no support for inheritance, then maybe there are some less-crumbling ways to solve this problem (without a radical change in the existing level of the model in general and without its decomposition in particular)?

I have one solution, but I would like to know how you solve this problem.


Rilm has support for implementing RealmModel instead of inheriting RealmObject from the model class. Please note that you need to add the @RealmClass annotation, maybe that's why it didn't work … Is this your case?

But generally speaking, over a year or more of using Rilm in production projects, we have never had such a problem that we had to implement RealmModel. Perhaps it is worth revising the class hierarchy? Models are tables of the base, maybe it's not worth it that they inherit some other objects, and acquire additional behavior that is not related to the database? What if you replace inheritance with an implementation of the interface of your class A?

class B extends RealmObject implements A {
. . . 
// your fields
. . .

Simply, well, what is it about this class A to actually inherit it and not to implement the interface?

Scroll to Top