1

Given the following answer to a question posted here previously, how would I change the fac function to take a constructor argument?

class BalanceActor[T <: Actor](val fac: () => T) extends Actor {
  val workers: Int = 10

  private lazy val actors = new Array[T](workers)

  override def start() = {
    for (i <- 0 to (workers - 1)) {
      actors(i) = fac() //use the factory method to instantiate a T
      actors(i).start
    }
    super.start()
  }
}
1
  • I'm curious about the down-vote on this question. Could whoever did it explain? Jan 18, 2013 at 20:09

1 Answer 1

5

For a String argument:

class BalanceActor[T <: Actor](val fac: String => T) extends Actor ...

For an A argument:

class BalanceActor[A, T <: Actor](val fac: A => T) extends Actor ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.