I have an enum class, which I want to initialize in few ways.
Therefore I have a few constructors.
I use the name of the enum item - this.name. That’s a const.
But Kotlin prevents me from using it:
constructor(…) : this(…, MetricDetail(metricName = this.name.toLowerCase().replace(’_’, ‘.’)))
This fails because it accesses “this”.
I think for this case it is no problem to allow access, since “this.name” is a const which comes with the class.
I have tried other ways, like an init() function like I do in Java, but then, Kotlin things the val’s are not initialized.
So in the end, I need to copy the init code to all constructors.
Thanks for considering.