Kotlin Program using Enum Class Implementing Interfaces

bookmark

package net.javaguides.kotlin.examples

interface ICardLimit {
    fun getCreditLimit(): Int
}

enum class CardType: ICardLimit {
    SILVER {
        override fun getCreditLimit() = 100000
    },
    GOLD {
        override fun getCreditLimit() = 200000
    },
    PLATINUM {
        override fun getCreditLimit() = 300000
    }
}

fun main(args: Array < String > ) {
    val creditLimit = CardType.PLATINUM.getCreditLimit()
    println(creditLimit);
}

 


Output:
300000