【发布时间】:2015-04-29 18:43:33
【问题描述】:
我仍然习惯于 Scala 中的 PartialFunction 概念。 我遇到了以下我无法理解的声明:
更新: def msgsToGet: PartialFunction[Any, Unit] 在 trait 中定义如下:
trait MyActorTrait {
palindrome: String => def msgsToGet: PartialFunction[Any, Unit]
//After the answers I received, I understand that the "def msgsToGet: //PartialFunction[Any, Unit]" represents the LHS of an abstract (as yet) //unimplemented function (no function body yet)
}
现在,这是什么意思?
我知道'def'表示一个函数。在本例中,它是一个名为 msgsToGet 的函数。
然后是一个冒号 (:)。好吧,直到现在,我一直认为“冒号后,是类型,这就是我迷路的地方。 好吧,是不是和以下一样:
def msgsToGet(): PartialFunction[Any, Unit]
[一个不接受参数并返回PartialFunction[Any, Unit]类型的函数。
PartialFunction[Any, Unit] 对我来说有点像返回类型。但是没有函数体。请问这是怎么回事?
这是一个更长但可读的语法糖吗?
请帮我解释一下..
【问题讨论】:
标签: scala