Finalising Enumerations for Scala 3

@uncomment_to_crush Thank you for your question. As it stands currently, enums can not be extended by other classes/traits/enums. If I have understood correctly, you could require cases to be defined by declaring AnyFSM as a trait, and another trait AnyFSMCompanion to hold the cases:

trait AnyFSM { enumCase: scala.reflect.Enum => }

trait AnyFSMCompanion {
  val Begin: AnyFSM
  val End: AnyFSM
  def values: Array[? <: AnyFSM]
}

enum MyFSM extends AnyFSM {
  case Begin
  case End
  case Other
}

object MyFSM extends AnyFSMCompanion

The example above works because the cases in an enum are defined in the companion object of the enum.

2 Likes

I believe the primary purpose of ordinals is for optimised collection implementations, such as EnumSet and EnumMap. Iā€™m not sure what Java does wrt serialization of enums, but I think it would be a good idea regardless to change the SerialVersionUID if you change the enum