Quantcast
Channel: How do I create an enum from an Int in Kotlin? - Stack Overflow
Viewing all articles
Browse latest Browse all 13

How do I create an enum from an Int in Kotlin?

$
0
0

I have this enum:

enum class Types(val value: Int) {    FOO(1)    BAR(2)    FOO_BAR(3)}

How do I create an instance of that enum using an Int?

I tried doing something like this:

val type = Types.valueOf(1)

And I get the error:

Integer literal does not conform to the expected type String


Viewing all articles
Browse latest Browse all 13

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>