获取

摘要 乐趣 <t : Any> getValue(propertyName : string , clazz : KClass < T >): t

返回特定的非空值属性的值。

class参数必须是属性的RealmStorageTypeKClass

以下代码片段概述了可用于不同值类型的不同函数:

// Retrieve a nullable int from a 'nullableIntField' property
dynamicRealmObject.getNullableValue("nullableIntField", Int::class)

// Retrieve a non-nullable int from an 'intField' property
dynamicRealmObject.getValue("intField", Int::class)

// Retrieve an object from an `objectField' property
dynamicRealmObject.getObject("objectField", DynamicRealmObject::class)

返回

属性值。

参数

属性 名称

要检索其值的属性的名称。

clazz

值的 Kotlin 类。 必须与 Realm 中属性的RealmStorageType.kClass匹配。

t

值的类型。

抛出异常

如果类不包含具有特定名称的字段、 clazz与属性的RealmStorageType.kClass不匹配或者尝试检索集合属性。