Hello guys, let me ask you something. Can we dyna...
# announcements
g
Hello guys, let me ask you something. Can we dynamically create a companion object from a map? For example, if we have a map with a hundred of keys and values, can we create a companion object so we could use it like the following?
Copy code
println(MyClass.myMapKey1)
println(MyClass.myMapKey2)
...
println(MyClass.myMapKeyN)
Maybe somehow a way to eval a code? Or another technique? (I would like to use this with kotlin-dsl.) My motivation is that I would like to retrieve a map from a properties file (a yaml one), but if possible, I would like to access my keys like if I was using an enum. Since the nature of this properties could be dynamic and they could change, it’s not a good idea to use a enum or a class with a defined companion object. We could access this keys as usual
myMap["myMapKey1"], ..., myMap["myMapKeyN"]
but I would like to avoid typos and use it like an enum, improving the experience with autocompletion. Can we achieve something like that?