Navigation

RealmAny (beta) - Android SDK

New in version 10.6.0.

Note

This feature is currently in beta. While we encourage you to try out the feature and give feedback, please be aware the API may change.

You can use the RealmAny data type to create Realm object fields that can contain any of several underlying types. You can store multiple RealmAny instances in RealmList, RealmDictionary, or RealmSet fields. To change the value of a RealmAny field, assign a new RealmAny instance with a different underlying value. In Realm Sync backend object schemas, the RealmAny data type is called mixed. RealmAny fields are indexable, but cannot be used as primary keys.

Note
RealmAny Type Compatiblility

RealmAny objects can refer to any supported field type except:

  • RealmAny
  • RealmList
  • RealmSet
  • RealmDictionary

To create a RealmAny instance, use the RealmAny.valueOf() method to assign an initial value or RealmAny.nullValue() to assign no value. RealmAny instances are immutable just like String or Integer instances; if you want to assign a new value to a RealmAny field, you must create a new RealmAny instance.

Important
Null RealmAny Values

RealmAny instances are always nullable. Additionally, instances can contain a value of type RealmAny.Type.NULL.

You can query a RealmAny field just like any other data type. Operators that only work with certain types, such as string operators and arithmetic operators, ignore values that do not contain that type. Negating such operators matches values that do not contain the type. Type queries match the underlying type, rather than RealmAny. Arithmetic operators convert numeric values implicitly to compare across types.

To subscribe to changes to a RealmAny field, use the RealmObject.addChangeListener method of the enclosing object. You can use the ObjectChangeSet parameter to determine if the RealmAny field changed.

Give Feedback

On this page

  • Usage
  • Queries
  • Notifications