2017-01-25 5 views
1

BaseModelからモデルを拡張してからRealmModelを実装しようとしています。他のクラスを拡張してRealmModelを実装することは可能ですか?

@RealmClass 
public class User extend BaseModel implements RealmModel 

しかし、それはエラーを投げている:

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

助けてください。

+0

できません。この問題を回避する方法を知りたい場合は、この回答を確認してください。http://stackoverflow.com/a/41552457/3503855 – AnixPasBesoin

+0

しかし、RealmModelインターフェイスのポイントは何ですか。 – crysis

答えて

0

RealmのGitHubリポジトリで説明したように、継承と多型はRealmではまだ実装されていません。貢献者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.

あなたはhere詳細を読むことができます。

私は当面、あなたのクラスを書く別の方法を考える必要があると思います。

0

非常に残念ですが、RealmObjectからプロパティとメソッドを継承する必要がないように、RealmModelが存在します。

@Ignoreが注釈されたフィールドのみを含む基本クラスを拡張しようとしましたが、even that is not supported at the momentです。

「フィールドを共有する」方法は、インターフェイス経由でアクセサを共有することだけです。

関連する問題