对于以下检查可被 3 整除的 Actor:
class CheckActor(actor: Actor) extends Actor {
println("created actor")
var sum = 0
def act = loop {
react {
case x:Int if (x % 3 == 0) => sum+=1
...
case "calcSum" => sum
case _ =>
}
}
}
当我尝试sum
从 CheckActor 实例中获取值时...
actor1 ! "calcSum" // actor1 is of type "CheckActor"
我在 sum1 的类型不匹配上看到了这个错误。
$>scalac Count.scala
Count.scala:38: error: type mismatch;
found : Unit
required: Int
val sum1: Int = actor1 ! "calcSum"
^
one error found