RealmAny - Java SDK
On this page
New in version 10.6.0.
Note
New Java SDK apps cannot use RealmAny
New App Services Apps
will not be able to synchronize data models with properties of type RealmAny
.
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 Atlas App Services 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
Usage
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.
Warning
Two Possible Null RealmAny Values
RealmAny
instances are always nullable. Additionally, instances can contain a value
of type RealmAny.Type.NULL
.
Queries
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.
Notifications
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.