Where is the akka class defined?

I am new to Scala.

In one of the Actor classes, I can see that my colleague of me defines code like this

import akka.actor.Actor

class Processor extends Actor {

  def receive: Receive = {
    case msg: String => doProcess(msg)
    case _ => 
  }
}

      

Where is this class defined? It is not imported into this class. How the system will find the Receive class

+3


source to share


3 answers


It is an alias for a type PartialFunction[Any, Unit]

defined within a akka.actor.Actor

companion object and its properties, respectively.

Excerpt from source code :



object Actor {
    // Type alias representing a Receive-expression for Akka Actors.
    type Receive = PartialFunction[Any, Unit]
    // ...
}

trait Actor {
    // to make type Receive known in subclasses without import
    type Receive = Actor.Receive
    // ...
}

      

+6


source


Receive

is a type alias for PartialFunction[Any,Unit]

. This type alias is defined in the Actor

companion object, which is then redefined by trait Actor

(thus available in Actor

impls), referencing the one defined on the companion.



+1


source


Receive is an alias for the type PartialFunction [Any, Unit]

See Actor source code here

You can also write the receive method as

def receive: PartialFunction[Any, Unit] = {
    ….
 }

      

+1


source







All Articles