Good day, I'm using reflection method to handle th...
# announcements
h
Good day, I'm using reflection method to handle the last call method example
Copy code
fun foo(name: String) {
  lastCallMethod = ::foo
}
Now I want to call the method
lastCallMethod
May I ask if there is a way to retrieve the
name
String that pass using reflection?
z
Nope. Even if you used a lambda instead of a function reference,
name
would only be captured if it were actually used inside the lambda, and there’d still be no way to get it out of the lambda object (short of very sketchy reflection tricks). You’d need to create a class to hold both the function reference and the name.
h
Got it, thank you
e
what is
lastCallMethod
? if it's
Copy code
var lastCallMethod: KFunction<*>? = null
lastCallMethod = ::foo
lastCallMethod?.name
could work, but not if it's
() -> Unit
or similar (without casting)