they are basically to establish a limited number of options which a value can be assigned to.
For instance:
// 0 is printed book, 1 is ebook
val bookType: Int = 0
But using this approach, you can assign an invalid value to this variable (2 for example)
Creating a
enum
you limit the options to the two (or more if you want) possible values.
enum class BookType { PRINTED, EBOOK }
So now you can define a variable/constant as
val bookType: BookType = PRINTED
and you canβt assign an invalid value to `bookType`β¦