Is it possible to declare an Enumeration object and class on the same level in Scala?
I started with this, but I am not sure what is the best way to register the instances.
object Gender extends Enumeration {
val MALE = new Gender(0)
val FEMALE = new Gender(1)
}
class Gender(val id: Int) extends Gender.Value {
}
The motivation for this is that I don’t want to refer to the enum class as Gender.Gender, but Gender.
This works:
However I do not really feel good about it. I think it would be better either
to make a type alias (if you can at this scope):
Or
importthe type before you use it:(Or, if you can, use case classes).