I was wondering how to apply a match and case to my act() method. This is my tempObject class
case class tempObject(typeOfData: Int) {}
And this is my Actor:
object StorageActor extends Actor {
def act(TO: tempObject) = TO match {
case TO(0) => println("True")
case TO(1) => println("False")
}
}
So, what should happen is, when I 开发者_JAVA技巧pass an object to act(), it calls the desired method, depending upon the values inside of the object. Is the above code correct to perform what I desire?
The act
method on the Actor
class is not supposed to be called with a value. It picks the values form the actor's mailbox and works on them. The correct way to do it is this:
case class TempObject(typeOfData: Int)
object StorageActor extends Actor {
def act() {
loop {
react {
case TempObject(0) => println("True")
case TempObject(1) => println("False")
}
}
}
}
StorageActor.start
StorageActor ! TempObject(0)
StorageActor ! TempObject(1)
精彩评论