Ordinal property

Report a typo

What is the output of this code?

enum class Rainbow(val colorName: String) {
    RED("Red"),
    ORANGE("Orange"),
    YELLOW("Yellow"),
    GREEN("Green"),
    BLUE("Blue"),
    INDIGO("Indigo"),
    VIOLET("Violet"),
    NULL("")
}

fun findByName(name: String): Rainbow {
    for (color in Rainbow.entries) {
        if (name == color.colorName) return color
    }
    return Rainbow.NULL
}

fun main() {
    val color = findByName("Black")
    println(color.ordinal)
}
Enter a short text
___

Create a free account to access the full topic