February 2018
Intermediate to advanced
350 pages
7h 35m
English
Enum in Kotlin is a way to define a set of constant values. Enums are very useful, but not limited, as configuration values:
enum class Flour { WHEAT, CORN, CASSAVA}
Each element is an object that extends the Flour class.
Like any object, they can extend interfaces:
interface Exotic { fun isExotic(): Boolean}enum class Flour : Exotic { WHEAT { override fun isExotic(): Boolean { return false } }, CORN { override fun isExotic(): Boolean { return false } }, CASSAVA { override fun isExotic(): Boolean { return true } }}
Enum can also have abstract methods:
enum class Flour: Exotic { WHEAT { override fun isGlutenFree(): Boolean { return false } override fun isExotic(): Boolean { return false } }, CORN { override fun isGlutenFree(): Boolean ...Read now
Unlock full access