v1.24.1
ValueEnum
ValueEnum is a new way for defining Scala enums, representing enum constants as final vals in companion object of enum class.
Advantages:
- feature parity with Java enums (although
ValueEnumdoes not extendjava.lang.Enum) - every enum constant has
name(name of thefinal valthat declares the constant) andordinal(zero based index of enum constant, consistent with declaration order). - less boilerplate than sealed hierarchy based enums
- it's possible to declare many enum constants in a single line of code
- much less generated classes, which is advantageous primarily for JS size reduction
Disadvantages:
- scalac exhaustive pattern match checking does not understand
ValueEnumwhich may result in both lack of correct warnings and incorrect warnings - each enum constant can't have its own API (unless through implicit classes)