It is possible, use id method.
scala> object E extends Enumeration {
val A = Value(1)
val B = Value(7)
val C = Value(2)
}
defined object E
scala> E.A.id
res7: Int = 1
scala> E.B.id
res8: Int = 7
scala> E.C.id
res9: Int = 2
Enumeration values can also be easly compared
scala> E.A < E.B
res10: Boolean = true
scala> E.C < E.B
res11: Boolean = true
scala> E.B < E.A
res12: Boolean = false
Refer to documentation for more
Edit
Your code in the picture is wrong. Firstly, as in your original code (that is not in the picture), SimpleEnum should be an object, not a class. As soon as you make that change your code won't compile and that should ring a bell.
You want SimpleClass to be able to wrap your enum values. Type of those values (i.e. ONE, TWO, THREE) is not SimpleEnum, it is SimpleEnum.Value. Objects of this type have id method.
class SimpleClass(se: SimpleEnum.Value) extends Ordered[SimpleEnum.Value] {
override def compare(that: SimpleEnum.Value): Int = se.id
}
A common thing to do is to declare a type alias for Value with exact same name as the enum object. Then you can import this type and use it
object SimpleEnum extends Enumeration {
type SimpleEnum = Value
val ONE = Value(1)
val TWO = Value(2)
val THREE = Value(3)
}
import SimpleEnum.SimpleEnum
class SimpleClass(se: SimpleEnum) extends Ordered[SimpleEnum] {
override def compare(that: SimpleEnum): Int = se.id
}
Note that Enumeration#Value already implements Ordered[Value]. You can verify it in the docs that I linked earlier.
There is no classic java enum in scala, but because the language is so cool, it was possible to create a regular class called Enumeration that with some tricks allows for similar behavior.