Kotlin data class: how to read the value of property if I don’t know its name at compile time?
Here is a function to read a property from an instance of a class given the property name (throws exception if property not found, but you can change that behaviour): import kotlin.reflect.KProperty1 import kotlin.reflect.full.memberProperties @Suppress(“UNCHECKED_CAST”) fun <R> readInstanceProperty(instance: Any, propertyName: String): R { val property = instance::class.members // don’t cast here to <Any, R>, it … Read more