Value of Field of an enum class


#1
import java.awt.*
enum class Colors(rgbValue : Color , byteValue : Byte){
    Pink(Color(255,105,180), 2.toByte()),
    Green(Color(0,128,0) , 3.toByte()),
    Orange(Color(255,140,0) , 4.toByte()),
    Yellow(Color(255,255,0) , 5.toByte()),
    Cyan(Color(0,255,255) , 6.toByte());
}
fun getColor(value : Byte){
    for (i in Colors.values()) {
        if (i.byteValue == value)
            println(true)
    }
}

Is this method of getting value of a field of an instance of an enum class wrong?
The IDE displays a message Unresolved Reference : byteValue.


#2

Colors does not have any properties. It only has constructor parameters rgbValue and byteValue. Prepend val to the parameters to convert them to properties.

https://kotlinlang.org/docs/reference/properties.html


#3

Thanks