我正在学习Scala和Akka,我基本上是Java程序员。我看到了各种语法,但很少有人无法理解。Scala语法很难理解
case class ProcessStringMsg(string: String)
case class StringProcessedMsg(words: Integer)
class StringCounterActor extends Actor {
def receive = {
case ProcessStringMsg(string) => {
val wordsInLine = string.split(" ").length
sender ! StringProcessedMsg(wordsInLine)
}
case _ => println("Error: message not recognized")
}
}
这里,sender ! StringProcessedMsg(wordsInLine)
是什么意思?
这只是一个【制法】(http://doc.akka.io/api/akka/current/index.html#[email protected](留言:任何) (implicitsender:akka.actor.ActorRef):Unit)call。方法可以(并且经常)在Scala中具有象征意义。 – alextsc
好心解释!操作员会请。 – Sun
这不是一个操作符,它只是一个方法调用。它调用'!'方法。就是这样。 –