Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 意义ref@Ping在阿克卡接受_Scala_Pattern Matching_Akka_Actor - Fatal编程技术网

Scala 意义ref@Ping在阿克卡接受

Scala 意义ref@Ping在阿克卡接受,scala,pattern-matching,akka,actor,Scala,Pattern Matching,Akka,Actor,我在akka上浏览了一些代码示例,发现了一个我想确定其含义的特定示例: def receive:receive={ 案例original@Ping(x) =>//做事 case=>//做事 } Ping是示例中用于消息的case类。 但是那原版的是什么意思呢?是发信人吗?如果是,这种方法是否比使用sender变量有任何优势 对不起,我不能给你链接,因为我再也找不到了 不确定这是Akka的东西还是我不知道的高级Scala模式匹配功能 找到答案的最简单方法是尝试: case class Ping(

我在akka上浏览了一些代码示例,发现了一个我想确定其含义的特定示例:

def receive:receive={
案例original@Ping(x) =>//做事
case=>//做事
}

Ping
是示例中用于消息的case类。 但是那原版的是什么意思呢?是发信人吗?如果是,这种方法是否比使用
sender
变量有任何优势

对不起,我不能给你链接,因为我再也找不到了

不确定这是Akka的东西还是我不知道的高级Scala模式匹配功能


找到答案的最简单方法是尝试:

case class Ping(x: Int)

scala> val msg = Ping(10)
msg: Ping = Ping(10)

scala> msg match {
     |    case original @ Ping(x) => {
     |        println("Original: " + original)
     |        println("x: " + x)
     |    }
     |    case _ => println("no match")
     | }
Original: Ping(10) // Printed the entire msg that was matched
x: 10              // Printed just the value x that was matched

所以
original
相当于
msg
,它是
Ping(10)
@
符号允许您将整个匹配对象分配给标识符。

最简单的方法是尝试:

case class Ping(x: Int)

scala> val msg = Ping(10)
msg: Ping = Ping(10)

scala> msg match {
     |    case original @ Ping(x) => {
     |        println("Original: " + original)
     |        println("x: " + x)
     |    }
     |    case _ => println("no match")
     | }
Original: Ping(10) // Printed the entire msg that was matched
x: 10              // Printed just the value x that was matched

所以
original
相当于
msg
,它是
Ping(10)
@
符号用于将整个匹配对象分配给标识符。

这是一种称为
变量绑定的Scala功能。它将匹配的值绑定到变量。您可以在这里找到更多示例

这是一种称为
变量绑定的Scala功能
。它将匹配的值绑定到变量。你可以在这里找到更多的例子