An enum class lets you create a set of values that represent the only valid values for a variable. Each value in an enum class is a constant. Each enum constant exists as a single instance of that enum class.
Enum class Represent a fixed set of named constants — like states, directions, or modes. Each constant is a singleton instance of the enum class. Can hold properties and functions.
An enum class can have a constructor, used to initialize each enum value. This works because each value defined by the enum class is an instance of that class.
Each value defined in an enum class can override the properties and functions it inherits from the class definition.
Enum class Built-in Properties and Methods
1. name: Returns the name of the constant as a String
2. ordinal: Returns the zero-based position in the declaration
3. entries: Returns an immutable list of all constants (Modern Kotlin). Replaces the older .values() array method
4. valueOf(string): Finds a constant by its name string
Telegram Group: https://t.me/androidNinjaWarrior
Guide to watch:
00:32 What is Enum Class in Kotlin?
02:27 How to create enum class in kotlin?
11:20 Built-in Properties and Methods in Enum class
#enum #enumclass #ordinal #entries #constant #enumkotlin #kotlin #advanceKotlin
Disclaimer- Some content are used for educational purposes under fair use.
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use. All credit for copyright material used in the video goes to the respected Owner.
Thank you guys.