```fun x(a: String) { print(::a.name) // Refer...
# announcements
a
Copy code
fun x(a: String) {
    print(::a.name) // References to variables aren't supported yet.
}
val someVar = 1;
x(someVar) // ::a.name should be someVar
Is there a way to know the name of a property or a variable passed to the function by reflection?
e
Maybe something like this could help you:
Copy code
fun x(a: String = "") {
    println(this::x.parameters.first().name)
}

x()
// prints: a
I.e. a reference to the function and then get its parameters, but then you must know the parameter's index (or just take the first like I did here)
Ah, I see you've edited your question and my answer is probably not what you're looking for
a
Yeah, I guess there is no way, right?
e
I guess not.
It seems to me that if you need the name of something from outside of the function's scope, then you should pass that name in as a parameter. It's the outside scope that knows this name, after all. If there even is a name.
Because
Copy code
val name = ""
x(name)
and
Copy code
x("")
behave the same, but in your case you probably want different behaviour in
x
.
a
Yeah. I guess I will pass from outside.