Hello Friend,
Today I am going to share about Enum class in Kotlin
- How to create/initialize enum classes
- methods and properties of enum classes.
Initializing enums –
Now we can easily access the color of fruits,
Enum Methods-
Enum Properties-
Hope this will help some one.
Enjoy Coding... :)
Today I am going to share about Enum class in Kotlin
- How to create/initialize enum classes
- methods and properties of enum classes.
Initializing enums –
Now we can easily access the color of fruits,
Enum Methods-
- values: This method returns a list of all the constants defined within the enum class.
- valueOf: This methods returns the enum constant defined in enum, matching the input string. If the constant, is not present in the enum, then an IllegalArgumentException is thrown.
Enum Properties-
- ordinal: This property stores the ordinal value of the constant, which is usually a zero-based index.
- name: This property stores the name of the constant.
Below is the example which help us to understand the uses of Enum method and Properties.
Outputs:
Hope this will help some one.
Enjoy Coding... :)
0 comments:
Post a Comment