abstract class C[T] {
  def lee: T
}

class CE[T <: Enumeration](val enum: T) extends C[enum.Value] {
  def lee = enum.values.toList(0)
}

The error I receive is: Expression of type CE.this.type##enum#Value doesn't conform to expected type enum.type#Value

I'm working with Scala 2.10.4. My intention is to write generic code on enums.

有帮助吗?

解决方案

I think you need:

class CE[T <: Enumeration](val enum: T) extends C[T#Value] {
  def lee = enum.values.toList(0)
}

which you can create with:

val c = new CE[Days.type](Days)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top