fun <reified T : RealmModel> Realm.createObject(): T
Instantiates and adds a new object to the Realm.
This method is only available for model classes with no @PrimaryKey
annotation.
If you like to create an object that has a primary key, use createObject instead.
T
- the Class of the object to create.
RealmException
- if the primary key is defined in the model class or an object cannot be created.
Return
the new object.
fun <reified T : RealmModel> Realm.createObject(primaryKeyValue: Any?): T
Instantiates and adds a new object to the Realm with the primary key value already set.
If the value violates the primary key constraint, no object will be added and a RealmException will be thrown. The default value for primary key provided by the model class will be ignored.
T
- the Class of the object to create.
primaryKeyValue
- value for the primary key field.
RealmException
- if object could not be created due to the primary key being invalid.
IllegalStateException
- if the model class does not have an primary key defined.
IllegalArgumentException
- if the primaryKeyValue
doesn't have a value that can be converted to the
expected value.
Return
the new object.