Nishoobansal
07/04/2020, 2:47 PMnglauber
07/04/2020, 3:53 PM// 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`…Michael de Kaste
07/04/2020, 6:57 PMrajesh
07/05/2020, 9:16 AM