1

I'm trying to extend my model from a BaseModel and then implement RealmModel.

@RealmClass
public class User extend BaseModel implements RealmModel

But it is throwing an error:

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

Please help.

crysis
  • 1,514
  • 1
  • 20
  • 35

2 Answers2

0

As mentioned in Realm's GitHub repository, inheritance and polymorphism are not implemented in Realm just yet.

As one of the contributors described it:

Realm currently is using byte code manipulation to replace field accessors and using annotation processor to create proxy classes. Enabling RealmObject to extend from the other class/abstract class will increase a bit complexity of Realm. So it is not implemented right now. But I agree it is something we should support.

You can read more here.

I guess that for the time being, you will have to think of another way to write your classes.

Community
  • 1
  • 1
Matan Itzhak
  • 2,702
  • 3
  • 16
  • 35
0

It is very unfortunate, but RealmModel exists so that you don't need to inherit properties and methods from RealmObject.

I tried extending a base class that only contained fields annotated with @Ignore, but even that is not supported at the moment.

Only way to "share fields" is to share the accessors through interface.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428