Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm model classes must either extend RealmObject or implement RealmModel to be considered a valid model class

I am getting below compilation error

Realm model classes must either extend RealmObject or implement RealmModel to be considered a valid model class

In this particular scenario

class Animals extends RealmObject { 

}

class Dog extends Animals { 

}

I am getting this error for the Dog class.

That error appears when I am indirectly extending RealmObject. i.e Dog is extending Animals (which in turns extends RealmObject), not RealmObject directly.

like image 637
Amit Yadav Avatar asked May 19 '16 08:05

Amit Yadav


2 Answers

While the issue has not been closed yet, it is recommended to use composition instead of inheritance: F.ex. you could have

public interface Animalistic {
    makeNoise();
}

which is then implemented by each animal.

like image 135
serv-inc Avatar answered Oct 21 '22 16:10

serv-inc


Inheritance / Polymorphism is still an open issue in Realm, Check this link https://github.com/realm/realm-java/issues/761

like image 12
Ashish Lingayat Avatar answered Oct 21 '22 16:10

Ashish Lingayat