Question

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.

Était-ce utile?

La solution

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)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top