I';我对使用2.7.7-Main$$anon$1$$anonfun$1$$anonfun$apply$2的scala脚本有问题

I';我对使用2.7.7-Main$$anon$1$$anonfun$1$$anonfun$apply$2的scala脚本有问题,scala,actor,Scala,Actor,这是我在一本书中使用的代码 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 !

这是我在一本书中使用的代码

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?"
错误
java.lang.NoClassDefFoundError:Main$$anon$1$$anonfun$1$$anonfun$apply$2

我猜您只是使用scala执行,而不是编译。如果编译该脚本(并将其包装在Application trait singleton对象中),则该脚本确实有效:

当我编译它时,我会得到以下文件:

  • ActorTest$$anonfun$1$$anonfun$apply$2$$anonfun$apply$1.class
  • ActorTest$$anonfun$1$$anonfun$apply$2.class
  • ActorTest$$anonfun$1.class
  • ActorTest$.class
  • ActorTest.class
如果我用scala-cp调用它。ActorTest我得到这个:

ricoeur:~ tom$ scala -cp . ActorTest I've got 6 messages in my mailbox. I've got 5 messages in my mailbox. I've got 4 messages in my mailbox. ^C 里科尔:~tom$scala-cp。阿克托斯特 我的邮箱里有6条信息。 我的邮箱里有5条信息。 我的邮箱里有4条信息。 ^C 它会在“我的邮箱中有4条消息”输出后等待,直到我按Ctrl+C组合键将其删除


希望有帮助。

啊!你知道……是的谢谢。不要将演员与
应用程序混用。
ricoeur:~ tom$ scala -cp . ActorTest
I've got 6 messages in my mailbox.
I've got 5 messages in my mailbox.
I've got 4 messages in my mailbox.
^C