This is the code I used from a book…
import scala.actors.Actor._
val countActor = actor {
loop {
react {
case "how many?" => {
println("I've got " + mailboxSize.toString + " messages in my mailbox.")
}
}
}
}
countActor ! 1
countActor ! 2
countActor ! 3
countActor ! "how many?"
countActor ! "how many?"
countActor ! 4
countActor ! "how many?"
The error
java.lang.NoClassDefFoundError: Main$$anon$1$$anonfun$1$$anonfun$apply$2
I’m guessing you are executing with just scala rather than compiling. The script does work if you compile it (and wrap it in an Application-trait singleton object):
When I compile that, I get the following files:
If I invoke it with scala -cp . ActorTest I get this:
It sits and waits after the “I’ve got 4 messages in my mailbox” output until I Ctrl+C it.
Hope that helps.