Docs Menu

Annotation Type Required

On this page

  • io.realm.annotations

Implemented interfaces:

This annotation will mark the field or the element in io.realm.RealmList as not nullable.

When a field of type Boolean, Byte, Short, Integer, Long, Float, Double, String, byte[], Date is annotated with Required , it cannot be set to null and Realm will throw an exception if it happens.

Fields with primitive types are implicitly required. Note, String is not a primitive type, so in Java it is default nullable unless it is marked @Required . In Kotlin the reverse is true, so a String is non-null. To specify a nullable String in Kotlin you should use String? .

If this annotation is used on a RealmList , the annotation is applied to the elements inside the list and not the list itself. The list itself is always non-null. This means that a list marked with this annotation are never allowed to hold null values even if the datatype would otherwise allow it. Realm will throw an exception if you attempt to store null values into a list marked @Required .

Compiling will fail if the Required annotation is put an a io.realm.RealmList containing references to other Realm objects.

←  Enum RealmNamingPolicyio.realm.coroutines →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.