Why enums constrain values
📖 Scenario: Imagine you are building a simple app that tracks the status of orders in a store. Each order can only have one of a few fixed statuses, like Pending, Shipped, or Delivered. You want to make sure the status can never be set to something invalid by mistake.
🎯 Goal: You will create an enum class in Kotlin to hold the allowed order statuses. Then you will use this enum to assign and print the status of an order, showing how enums help keep values safe and limited.
📋 What You'll Learn
Create an enum class called
OrderStatus with values PENDING, SHIPPED, and DELIVEREDCreate a variable called
currentStatus and set it to OrderStatus.PENDINGChange
currentStatus to OrderStatus.SHIPPEDPrint the value of
currentStatus to show the current order status💡 Why This Matters
🌍 Real World
Enums are used in apps to keep data clean and predictable, like order statuses, user roles, or traffic light colors.
💼 Career
Understanding enums is important for writing safe, clear code in Kotlin, which is widely used for Android apps and backend services.
Progress0 / 4 steps