is it possible to write a function to get an enum ...
# announcements
k
is it possible to write a function to get an enum from a value? I know in Java you would write a static function, but enums in kotlin can't have companion objects. Looking to get the enum associated with
token
here.
Copy code
internal enum class BencoderTokens(private val token: Byte) {
    INTEGER('i'.toByte()),
    STRING(':'.toByte()),
    LIST('l'.toByte()),
    DICT('d'.toByte()),
    END('e'.toByte())
}
s
??? Enums can have companion objects.
Copy code
internal enum class BencoderTokens(private val token: Byte) {
    INTEGER('i'.toByte()),
    STRING(':'.toByte()),
    LIST('l'.toByte()),
    DICT('d'.toByte()),
    END('e'.toByte());

    companion object {
        fun create(...) : BencoderTokens { .. }
    }
}
k
welp, I'm dumb 🙃
thanks!