有时会发生如此神奇的事情,以至于我不知道编译器做了什么。例如在akka中,receive
定义为:
def receive: Receive
type Receive = Actor.Receive
并Receive
定义为:
type Receive = PartialFunction[Any, Unit]
然后我们声明receive
为:
def receive = {
case "a" => //do something
case "b" => //do something
case _ => //default
}
我知道PartialFunction
但我没有得到的是它如何将消息应用到receive
. 我们不是应该提供apply
andisDefinedAt
因为receive
返回 aPartialFunction
吗?
从语法上讲,它如何应用于receive
消息?它会做类似的message match receive
事情吗?