So, basically I would like the field to be a Strin...
# getting-started
d
So, basically I would like the field to be a String, but restricting it only to one of these 5
🧵 2
e
Maybe like this:
Copy code
enum class FRUIT {
    APPLE,
    ORANGE,
    PEAR,
    BANANA,
    PEACH
}

val apple: FRUIT = FRUIT.APPLE
val appleStr: String = apple.name // "APPLE"
val appleStr2 = "$apple" // "APPLE"
if you need different casing (or a different type) stored in enum:
Copy code
enum class FRUIT(val lowerCase: String) {
    APPLE("apple"),
    ORANGE("orange"),
    PEAR("pear"),
    BANANA("banana"),
    PEACH("peach")
}

val apple: FRUIT = FRUIT.APPLE
val appleStr: String = apple.lowerCase // "apple"
val appleStr2 = "$apple" // "APPLE"
d
@Eric Grimsborn fantastic!!! I didn’t know with enum you can access the name property!
that’s exactly what I was looking for!
many thanks!
đź‘Ť 1