Quantcast
Channel: How do I declare a variable of enum type in Kotlin? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

How do I declare a variable of enum type in Kotlin?

$
0
0

Following the documentation, I created an enum class:

enum class BitCount public constructor(val value : Int){  x32(32),  x64(64)}

Then, I'm trying to declare a variable in some function:

val bitCount : BitCount = BitCount(32)

But there is a compilation error:

Error:(18, 29) Kotlin: Enum types cannot be instantiated

How do I declare a variable of BitCount type and initialize it from an Int?


Viewing all articles
Browse latest Browse all 5

Trending Articles