ENUM
Enums help us in defining like a fixed key-value pairs and then use them. These are to be used like fixed pairs and need not be stored in database or be something that shows up dynamically. These are mostly fixed entries.
enum class ProductCategories(val cat: String, val id: Int) {
ELECTRONICS("Electronics", 0),
ACCESSORIES(cat = "Computer Accessories", 1),
PHERIPHERALS(cat = "Computer Pheripherals", id = 2); //This is a mandatory semi-colon
fun getEnumId() = id
fun categoryName() = cat
}
fun main(){
println(ProductCategories.ACCESSORIES.categoryName())
println(ProductCategories.PHERIPHERALS.categoryName())
}
Comments
Post a Comment