Enums with custom implementation


#1

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


#2

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


#3

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


#4

Exactly.