gpt4 book ai didi

scala - akka 类 Receive 定义在哪里?

转载 作者:行者123 更新时间:2023-12-02 12:55:57 25 4
gpt4 key购买 nike

我对 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com