Search code examples
scalaenumerationextending

How to extend existing enumerations objects in Scala?


I'm wondering if you can extend already existing enumerations in Scala. For example:

object BasicAnimal extends Enumeration{
    type BasicAnimal = Value
    val Cat, Dog = Value   
}

Can this be extended something like this:

object FourLeggedAnimal extends BasicAnimal{
    type FourLeggedAnimal = Value
    val Dragon = Value
}

Then, the elements in FourLeggedAnimal would be Cat, Dog and Dragon. Can this be done?


Solution

  • No, you cannot do this. The identifier BasicAnimal after extends is not a type, it is a value, so it won't work, unfortunately.