Alan Coromano
Alan Coromano

Reputation: 26018

Akka complains to a generic parameter

I have a class hierarchy like this:

abstract class Class1[T <: Class2 : ClassTag] extends Actor {

  protected val val1 = context.actorOf(Props[T])   // ops!
  //..........
}

abstract class Class2[T <: Actor] extends Actor {
//................
}

However, it complains type arguments [T] do not conform to method apply's type parameter bounds [T <: akka.actor.Actor]

How do I fix that?

Upvotes: 2

Views: 1063

Answers (1)

Jatin
Jatin

Reputation: 31724

The error is because you are not passing type parameter with Class2. Give the type parameter and it works:

abstract class Class1[T <: Class2[_] : ClassTag] extends Actor {
    protected val val1 = context.actorOf(Props[T])
}

Upvotes: 2

Related Questions