Hello, Is there the possibility in Kotlin to retr...
# getting-started
t
Hello, Is there the possibility in Kotlin to retrieve statically the return type or parameters of a function? In TypeScript it is possible to things like, I don't know about Kotlin.
Copy code
fun getSomething(): Something {}

val something: ReturnType<typeof getSomething> = getSomething()
It may be useful for situation where:
Copy code
fun executeSomething(cb: Something.(arg: String) -> Unit) {
    val something = Something()
    something.cb("the arg")
}

// here the type could be different
// val cb: Parameters<executeSomething>[0] = {
val cb: SecretUser.(arg: String) -> Unit = {
    println(propertyOfSomething)
}

executeSomething(cb)
I am just playing with the language 😊
l
If you are fine with inlining the function, you could use a reified generic. If not, on JVM, the best option I know of is reflection.
t
Thank you for answering. I'll take a look at it.