Accra Accor Chords factory

Akka and I met.

From: Akka 2.3.6 (current) Recommended Actor Practice

This is an example of a DemoActor actor:

class DemoActor(magicNumber: Int) extends Actor {
  def receive = {
    case x: Int => sender() ! (x + magicNumber)
  }
}

In the Recommended Practices section of the document, he reads: β€œIt’s a good idea to provide factory methods at each actor’s companion object that will help keep the ability to create the appropriate details as close as possible to the definition of an actor.” What they do like this:

object DemoActor {
  def props(magicNumber: Int): Props = Props(new DemoActor(magicNumber))
}

Question: What is the difference between specifying a factory method for a type attribute:

object DemoActor {
  def props(magicNumber: Int): Props = Props(classOf[DemoActor], magicNumber)
}

If you missed it, the difference was the argument of the Props constructor:

new DemoActor(magicNumber)

VS

classOf[DemoActor], magicNumber

akka , Props(classOf[ActorWithArgs], "arg1"): " " ", IllegalArgumentEception, ".

, ?!?....

+4
1

, ?!?....

, , . , , .

Props apply , :

Props(new DemoActor(magicNumber))

Props. , . Props apply:

def apply[T <: Actor](creator: β‡’ T)(implicit arg0: ClassTag[T]): Props

creator. , , .

, new , , . - , .

+10

All Articles