Reputation: 13
Everywhere is mentioned, Realm needs setters and getters on private field members to work correctly. Accidentially I used public members without setters / getters and the small example worked. Do I miss something (now or in future), where this approach wouldn't work anymore?
Is use Android Studio with io.realm:realm-gradle-plugin:0.91.0
Here is some code:
public class Contact extends RealmObject {
public String phone;
public String mail;
public String person;
}
and later ...
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);
}
Upvotes: 1
Views: 170
Reputation: 1651
Emanuele from Realm here. Realm has been supporting public fields with no accessors since 0.88.0 https://realm.io/news/realm-java-0.88.0/
Upvotes: 1