lundi 2 mai 2016

Can I get a KFunction from a variable of function type in Kotlin?

I'm trying to get the name that a function was defined with

fun aFunction() = Unit

fun functionName(function: () -> Unit) : String {
  val functionAsKFunction: KFunction<Unit> = someMiracle(function)
  return functionAsKFunction.name
}

assertEquals("aFunction", functionName(::aFunction)) 





Aucun commentaire:

Enregistrer un commentaire