Enums with custom implementation


The code

enum class Alphabet{   A{   var str: String = "Dzien dobry"   },   B,C,D }

The usage

println(Alphabet.A.str)  //this one fails to compile as property "str" is unknown println((Alphabet.A as Alphabet.A).str)  //awkward cast makes it work

It's not that it crashes or something but still kinda strange when one reads such code


It's a bug: the type Aplhabet.A should be private to itself so that the "awkward cast" is illegal.

YouTrack issue: https://youtrack.jetbrains.com/issue/KT-5401


Do you mean that accessing Alphabet.A.str will not be possible any more?