The Actor DSL example from Akka doc

前端 未结 1 1365
无人共我
无人共我 2021-01-21 02:04

I try to implement Actor DSL example from akk doc, but found error,

ambiguous implicit values: both method senderFromInbox in trait Inbox of type (implicit inbox

相关标签:
1条回答
  • 2021-01-21 02:35

    Short answer (only for REPL without :paste mode):

    val a = ...
    implicit val i = inbox()
    

    You should pass self, not null as second parameter (sender) of tell method. Method ! takes this parameter implicitly and invokes tell. There are 2 implicit ActorRef in scope of sender ! "hi": i and self (field of Act) - compiler can't figure out which one you need.

    You should remove implicit val i from scope of sender ! "hi".

    Correct solution - move actor creation to method and all other code - to other method. In REPL you could create a before i.

    Quick dirty solution - hide i like this:

    val a = {
      val i = 0
      actor(new Act {
      ...
    }
    
    0 讨论(0)
提交回复
热议问题