如何在Scala中扩展现有的枚举对象?

Hen*_*nry 6 enumeration scala extending

我想知道你是否可以在Scala中扩展现有的枚举.例如:

object BasicAnimal extends Enumeration{
    type BasicAnimal = Value
    val Cat, Dog = Value   
}
Run Code Online (Sandbox Code Playgroud)

可以这样扩展:

object FourLeggedAnimal extends BasicAnimal{
    type FourLeggedAnimal = Value
    val Dragon = Value
}
Run Code Online (Sandbox Code Playgroud)

然后,FourLeggedAnimal中的元素将是Cat,Dog和Dragon.可以这样做吗?

Jea*_*let 5

不,你不能这样做。BasicAnimal后面的标识符extends不是类型,而是值,因此不幸的是,它不起作用。