我正在努力寻找创建具有 self 类型的转换的新方法。
假设我有一个 Actor
trait BarPolicy {
val maxDrinksNumber:Int
}
trait ProductionPolicy extends BarPolicy {
val maxDrinksNumber = 5
}
object FooActor {
def apply() = new FooActor with ProductionPolicy
}
class FooActor extends Actor {
this: BarPolicy =>
}
有了该代码,我可以编写如下内容:
context.actorOf(Props(FooActor()))
现在这已被弃用,我只是找不到另一种方法来正确执行此操作。
根据 akka 的建议,“apply()”方法现在应该看起来像这样:
def apply() : Props = Props(classOf[FooActor])
但是我可以把 mixin 放在哪里呢?
最佳答案
object FooActor {
private class ProductionFooActor extends FooActor with ProductionPolicy
def apply() : Props = Props(classOf[ProductionFooActor])
}
也许是这样的?
关于scala - 使用包含 self 类型的 Prop 创建 Actor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20957743/