I'm trying to access the name of a variable inside an iterator
listOf(someClassVariable, anotherClassVariable, yetAnotherClassVariable).forEach {
if (it.foo()) {
map.add(it, ::it.name)
}
}
but getting unsupported [references to variables aren't supported yet] error at ::it.name. Any ideas/workarounds?
it.name? or do you actually want something like a supplier or similar that will return the name, when you access the supplier? (something like a lazy evaluation?)map.add(someClassVariable, "someClassVariable")::someClassVariable.namewould... what are you trying to accomplish that way? maybe there is another approach too... I mean: now you manually put all the variables into the list... if that becomes more dynamic maybe also the rest will solve itself more easily? ;-)