无法在Realm中初始化列表

时间:2018-11-24 14:19:46

标签: android realm

Android 3.2,java 1.7。领域4.1.0

此处代码:

public class LocalizedString extends RealmObject {
  private RealmList<TranslatedString> translations;

public void cascadeUpdate(Realm realm, LocalizedString that) {
        if (!EqualsUtil.areEqualContentLists(this.translations, that.translations)) {
            if (that.translations == null) {
                setTranslations(null);
            } else {
                if (translations == null) {
                    translations = realm.copyToRealm(new RealmList<TranslatedString>()); // error!!!
                }
            }
        }
    }


public class TranslatedString extends RealmObject {
    private String locale;
    private String value;
}

我需要在translations = null时初始化列表。所以我试试这个:

translations = realm.copyToRealm(new RealmList<TranslatedString>());

此处编译错误:

error: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<TranslatedString>

0 个答案:

没有答案