import akka.actor.Actor import akka.actor.ActorSystem import akka.actor.Props class HelloActor extends Actor { def receive = { case "hello" => println("您好!") case _ => println("您是?") } } object Main extends App { val system = ActorSystem("HelloSystem") // 缺省的Actor構造函數 val helloActor = system.actorOf(Props[HelloActor], name = "helloactor") helloActor ! "hello" helloActor ! "喂" }
運行時出現錯誤提示:scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOpsjava
個人系統scala版本是2.12(而且在idea的project settings--libraries中增長的是com_typesafe_akka_akka_actor_2_12_0_M1_2_4_M2庫),根據網上有人寫的提示做以下修改:ide
將scala-sdk從2.12換爲2.11函數
File -> Project Structure -> Global libraries -> Remove SDK -> Rebuild.ui
最終成功了。idea