Ensuring uniqueness of enum constants

If what you want is only an integer, and you don’t care which enum entry is associated with which integer, then you can use ordinal property instead.

Example:

fun main() {

  for (u in Unique.values()) { print(u.ordinal)}

}
​
enum class Unique {
    FIRST,
    SECOND,
    THIRD
    
}

Otherwise, I don’t see any better solution.

1 Like