I have a data class and I thought I’d write an extension method toMap
that uses reflection:
fun Thing.toMap(): MutableMap<String, Any?> {
val kc = this::class
val m = mutableMapOf<String, Any?>()
for (p in kc.memberProperties) {
m.put(p.name, p.get(this))
}
return m
}
The compiler says:
Out-projected type ‘KProperty1<out EmailVerificationAttempt, Any?>’ prohibits the use of ‘public abstract fun get(receiver: T): R defined in kotlin.reflect.KProperty1’
I’m wondering…
- What does that mean?
- What cast can I use to force it to work?