Overriding the method of a generic trait in Scala

Viewed 1396

I defined a generic Environment trait:

trait Environment[T]

For which I provide this implementation:

class MyEnvironment extends Environment[Integer] {
 val specific: Integer = 0
}

Furthermore, I defined a generic Event trait that has one method that accepts a generic Environment as parameter:

trait Event[T] {
  def exec(e: Environment[T])
}

For this Event trait, I provided the following implementation, where the exec() method accepts a parameter of the type MyEnvironment, to enable me to access the specific value of MyEnvironment.

class MyEvent extends Event[Integer] {
  override def exec(e: MyEnvironment): Unit = {
    println(e.specific)
  }
}

However, the Scala compilers outputs an error, from where it seems that MyEnvironment is not recognized as an Environment[Integer]:

Error: method exec overrides nothing.

Note: the super classes of class MyEvent contain the following, non final members named exec: def exec(t: main.vub.lidibm.test.Environment[Integer]): Unit

Is it possible to make this work, or are there patterns to circumvent this problem.

2 Answers
Related