Enumerations

An enumeration is a collection of names.

Kotlin’s enum class is a convenient way to manage these names:

// Enumerations/Level.kt package enumerations import atomictest.eq enum class Level { Overflow, High, Medium, Low, Empty } fun main(args: Array<String>) { Level.Medium eq "Medium" }

Here, the enum names represent various levels. Note that creating an enum automatically generates toString()s for the enum names.

End of sample. See AtomicKotlin.com for full early-access book.



Previous          Next

©2018 Mindview LLC. All Rights Reserved.