dimanche 23 juin 2019

Is there a safe way to get the name of a generic function in Kotlin?

I'm using ::func.name to safely get the name of functions in Kotlin. When I try to do this on a generic function, like this:

fun <T> test(x: T): List<T> = listOf(x)
println(::test.name)

I get the error

Type inference failed: Not enough information to infer parameter T in 

fun <T> test
(
x: T
)
: List<T>
Please specify it explicitly.

I tried println(::test<Int>.name) and println(::<Int>test.name) but neither worked.

I would expect theres a safe way of getting function references to generic functions.





Aucun commentaire:

Enregistrer un commentaire