考虑到以前在此处发布的问题的以下答案,我如何更改fac函数以获取构造函数参数?
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()
}
}
答案 0 :(得分:5)
对于String
参数:
class BalanceActor[T <: Actor](val fac: String => T) extends Actor ...
对于A
参数:
class BalanceActor[A, T <: Actor](val fac: A => T) extends Actor ...