Is it possible to get the name of a scala variable at runtime?
E.g. is it possible to write a function getIntVarName(variable: Int): String behaving as
getIntVarName(variable: Int): String
I don't think it's possible to get the name of a variable, but you can try it with objects:
object Test1 { def main(args: Array[String]) { object MyVar { def value = 1 } println(MyVar.getClass) } }
This prints: class Test1$MyVar$2$. So you can get 'MyVar' out of it.
class Test1$MyVar$2$