Overriding Scala Enumeration Value

The Enumeration values are instance of the Val class. This class can be extended and a factory method can be added.

object My extends Enumeration {
    val A = Value("name", "x")
    val B = Value("other", "y")
    class MyVal(name: String, val x : String) extends Val(nextId, name)
    protected final def Value(name: String, x : String): MyVal = new MyVal(name, x)
}

scala> My.B.id
res0: Int = 1

scala> My.B.x
res1: String = y

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)