val a = 5
println("a $a") // instead of this, we can call foo(a)
Calling println("a $a")
many times is suffer. Can we create a new function and just call foo(a)
?
val a = 5
println("a $a") // instead of this, we can call foo(a)
Calling println("a $a")
many times is suffer. Can we create a new function and just call foo(a)
?
It is not easily / directly possible (at the moment)...
Consider your fun
, you would have to do it with the following syntax:
fun foo(a: Any) {
println("'${::a.name}' : $a") // doesn't compile
}
Unfortunately, this feature is currently only available for properties and function names, but not for local variables (yet), according to this discussion and according to the most recent Kotlin Eclipse Plugin, because it shows me
Read the mentioned discussion and this question in order to find possible alternatives and more information in general.