0
votes
abstract class BaseActor[U: TaskUnit](master: ActorRef) extends Actor with ActorLogging {

    def receive = {
        ..
        ..

        case taskUnit: U => ...

    }

    def performTask(task: U): Future[_]
}

My TaskUnit looks like:

trait TaskUnit {
    def status(status: String): TaskResponse[_] 
}

I am getting 1 error and 1 warning which I need some advice on.

  1. I'm getting an warning saying TaskUnit does not take type parameters (this error is on the abstract class definition line)

  2. Warning saying the abstract type pattern U is unchecked since it is eliminated by erasure (this is for the case taskUnit: U line)

What is the problem with my current design?

1

1 Answers

4
votes

Well the reason you receive error is quite simple. You are writing:

abstract class X[U: Y]

But you probably meant something like this:

abstract class X[U <: Y]

Difference between those two definitions is quite significant. The second one signals, that type parameter U should be subtype of Y (including Y). But the first one is something different. It is translated to the following:

abstract class X[U](implicit ev: Y[U])

This syntax was introduced in order to make usage of type classes in scala with less boilerplate. I think you can see the source of your error right now. Compiler expects TaskUnit to be Type with exactly one type parameter:

TaskUnit[T] {
  ...
}

But it obviously don't have such shape.