October 2018
Intermediate to advanced
370 pages
9h 15m
English
Just like normal classes, the enum class is also able to implement interfaces. In this case, each member in the enum class will be responsible for providing the function body of each function signature that is mentioned in the interface.
Let's create an interface, printable, with one function, show(). Create an enum class, NEWS, and implement the printable interface:
interface printable { fun show() } enum class NEWS : printable { NORTH { override fun show() { println("Can you explain to me what summer is") } }, EAST { override fun show() { println("Can you explain to me what cold is") } }, WEST { override fun show() { println("I know what winter and summer are") } }, SOUTH { override fun show() { println("Oh ...Read now
Unlock full access