【问题标题】:Direct field access in Realm for AndroidRealm for Android 中的直接字段访问
【发布时间】:2016-05-25 10:09:13
【问题描述】:

到处都提到,Realm 需要私有字段成员的 setter 和 getter 才能正常工作。意外地,我使用了没有 setter / getter 的公共成员,并且这个小例子奏效了。我是否错过了某些东西(现在或将来),这种方法不再适用?

将 Android Studio 与 io.realm:realm-gradle-plugin:0.91.0 一起使用

这是一些代码:

public class Contact extends RealmObject {
    public String phone;
    public String mail;
    public String person;
}

以后...

realm.beginTransaction();
Contact contact = realm.createObject(Contact.class);
contact.mail="123";
contact.person="456";
contact.phone="789";
realm.commitTransaction();
final RealmResults<Contact> contacts = realm.where(Contact.class).findAll();
for (Contact c: contacts) {
   Log.i(TAG, "mail: " + c.mail);
   Log.i(TAG, "person: " + c.person);
   Log.i(TAG, "phone: " + c.phone);
}

【问题讨论】:

    标签: android realm setter getter


    【解决方案1】:

    来自 Realm 的 Emanuele。 Realm 从 0.88.0 https://realm.io/news/realm-java-0.88.0/987654321@开始就一直支持没有访问器的公共字段

    【讨论】:

    • 太棒了!这正是我正在搜索的信息,但在短暂检查变更日志时没有找到。再次感谢你:)
    • 很高兴能帮上忙! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多