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
You can use scala-nameof to get a variable name, function name, class member name, or type name. It happens at compile-time so there's no reflection involved and no runtime dependency needed.
val myInt = 3 assert("myInt" === nameOf(myInt))
will compile to:
val myInt = 3 assert("myInt" === "myInt")