Scala Enums - How to assign initial values?

object WeekDay extends Enumeration { type WeekDay = Value val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value } 

How would you set the initial value to WeekDay.Mon == 1 and WeekDay.Tue == 2 , etc. would be true?

Is there a constructor in Enumeration, Enumeration(initial: Int, names: String*) , is there a way I could use to create a WeekDay object?

+4
source share
1 answer

Try object WeekDay extends Enumeration(1) i.e. call the constructor of the enumerations.

The second parameter names: String* means that it accepts any number of string arguments - including not all, therefore only one argument.

+5
source

All Articles