标签:equal less cto case rgs object com could receive
package com.bjsxt.scala import scala.actors.Actor case class Message(actor:Actor,msg:String) class MyActor1 extends Actor { def act(): Unit = { while(true){ receive { case m:Message=>{ if(m.msg.equals("hello~")){ println("hello~") m.actor ! "hi~" }else if(m.msg.equals("could we have a dinner?")){ println("could we have a dinner?") m.actor ! "no..." } } case _=>{ println("no match...") } } } } } class MyActor2(actor:Actor) extends Actor { actor ! Message(this,"hello~") def act(): Unit = { while (true) { receive { case s: String => { if (s.equals("hi~")) { println("hi~") actor ! Message(this, "could we have a dinner?") } else if (s.equals("no...")) { println("no...") println("。。。。") } } case _ => { println("no match...") } } } } } object Lesson_Actor2 { def main(args: Array[String]): Unit = { val actor1 = new MyActor1() val actor2 = new MyActor2(actor1) actor1.start() actor2.start() } }
标签:equal less cto case rgs object com could receive
原文地址:https://www.cnblogs.com/huiandong/p/9278295.html