Java – real ORM: how to handle maps?
•
Java
I'm creating an Android application. I need to persist map < string, MyClass >
Solution
As you've noticed, real doesn't support maps yet: https://github.com/realm/realm-java/issues/759
You can use model classes:
class MyData extends RealmObject { private RealmList<MyMapEntry> myMap; } class MyMapEntry extends RealmObject { private String key; private MyClass value; }
Suppose you have a mydata object named mydata, and you want to get the value associated with MyKey, query MyClass, MyClass = mydata getMyMap(). where(). equalTo(“key”,myKey). Firstfirst() can be useful
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码