Kotlin Reflection not working on custom classes

Viewed 64

I have this wonderful method here:

fun Any.get(name : String) : Any{
    println(name)
    println(this::class.members.first{it.name == name} as KProperty1<Any,*>)
      return  (this::class.members.first { it.name == name } as KProperty1<Any, *>).get(this)!!
}

which I use with the class B:

open class Model(@Sql("id",true,true) var id : Int = 0)
open class A(val a : String, val b : User, @NoSql id : Int = 0) : Model(id)
class B(val c : Int, @NoSql a : String, @NoSql b : User, @NoSql id : Int = 0) : A(a,b,id)

When I try to retrieve the id, everything works as expected. But when I try to retrieve the User, it throws:

java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$Method cannot access a member of class com.gelbelachente.duckshit.db.models.ExtensionTest$A with modifiers "public final"
kotlin.reflect.full.IllegalCallableAccessException: java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$Method cannot access a member of class com.gelbelachente.duckshit.db.models.ExtensionTest$A with modifiers "public final"
    

Additionally the console output:

id
var com.gelbelachente.duckshit.db.models.ExtensionTest.B.id: kotlin.Int
b
val com.gelbelachente.duckshit.db.models.ExtensionTest.B.b: server.db.models.User
0 Answers
Related