title: Getting the correct scala actor sender reference when sending from an different class
body: <p>Within my actor I have to create a class which sends a message to another actor. The other actor should reply back to actor A</p>
  
  <pre><code>class A extends Actor {
  
  val b = new B
  b.start
  
  val i = new DefaultHandler() {
              override def fun(a: String) = {  
                  b ! payload
              }
          }
  someotherclass.registerHandler(i)
  
  def act = {
        loop {
          react {
            case reply =&gt; //do something
  
  }
  
  class B extends Actor {
  
  def act = {
        loop {
          react {
            case msg =&gt; sender ! reply
  
            }
  }
  </code></pre>
  
  <p>The problem now is that while sending from the inner class I'm not within the actor itself anymore and as a result actor B does not get a correct reference to actor B. One way to fix this would be to pass a reference to A via the message but this seems quite ugly to me.</p>
  
  <pre><code>val ref = self
  val i = new DefaultClass() {
              override def fun(a: String) = {  
                  b ! message(payload, ref)
              }
          }
  </code></pre>
  
  <p>Is there a more elegant way to solve this?  </p>