score:0

I don't think you need MessageType in the type parameters to accomplish what you want. Instead make MessageType equal to Message[From, this.type].

trait Handler[From <: Component] {
  type MessageType = Message[From, this.type]

  def handle(message: MessageType): Unit;
}

Consider making message covariant in its first parameter.

Note that this.type does not refer to the type that you are defining. this.type is a type that has only a single value: this. this doesn't exist outside the trait body, and therefore cannot be used in the type parameters. If you really need to refer to the type the trait will be mixed into, you need F-bounded polymorphism.


Related Query