我对 Scala 还很陌生。
在一个 Actor 类中,我看到我的同事定义了这样的代码
导入akka.actor.Actor
class Processor extends Actor {
def receive: Receive = {
case msg: String => doProcess(msg)
case _ =>
}
}
这个 Receive 类在哪里定义的?它没有导入到此类中。系统如何找到Receive类
最佳答案
它是分别在 akka.actor.Actor
伴随对象和特征中定义的 PartialFunction[Any, Unit]
的类型别名。
摘自source code :
object Actor {
// Type alias representing a Receive-expression for Akka Actors.
type Receive = PartialFunction[Any, Unit]
// ...
}
trait Actor {
// to make type Receive known in subclasses without import
type Receive = Actor.Receive
// ...
}
关于scala - akka 类 Receive 定义在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25786501/