Is it possible for me to create a function that wo...
# reflect
j
Is it possible for me to create a function that would look something like this?
Copy code
interface A { val field: Int }
data class B(override val field: Int): A

fun <T: A> myFunction(property: KProperty1<T, Int>? = null) {
    val kProperty = (property ?: A::field) as KProperty1<Any, Int>
    /* Something */
}

fun main() {
    myFunction(B::field)
}
Solved it with a small hack 👌
e
did you try
Copy code
fun myFunction(property: KProperty1<out A, Int>)
?
j
That doesn't work
I tried with
<out T, Int>
. But that breaks the usage of
kProperty.get
as now it requires a
Nothing
object instead of
T
or
A
.