簡體   English   中英

Scala:未進行隱式轉換?

[英]Scala: implicit conversion not made?

[error] DeviceAffiliationCluster.scala:56: value ask is not a member of akka.actor.ActorRef
[error]   def ask(msg: Any): Future[Any] = deviceRegion.ask(msg)
[error]                                                 ^
[warn] DeviceAffiliationCluster.scala:5: Unused import
[warn] import akka.pattern.ask

akka.pattern.ask提供了一個隱式轉換(從ActorRefAskableActorRef ,后者提供了ask方法)

但是,當我使用sbt進行編譯時,無法識別該轉換。 (Intellij看到了隱式轉換,對此沒有任何問題,但是我正在使用sbt進行構建。)

我可以使它明確工作:

val deviceRegion: ActorRef =  ...

val deviceRegionAskable: AskableActorRef = deviceRegion

問題是您的方法ask隱藏了從akka.pattern.ask導入的ask方法。如果您使用其他方法名稱,則您的示例可以正常工作

  import akka.actor._
  import akka.pattern.ask
  import scala.concurrent.duration._
  import scala.concurrent._

  class FooActor extends Actor {
    def receive = {
    case s: String => sender ! s"Hello $s"
    }}
  val ac = ActorSystem()
  implicit val ec : ExecutionContext = ac.dispatcher
  val fooAc = ac.actorOf(Props[FooActor], "fa")
  implicit val to = new akka.util.Timeout(10 seconds)
  def ask2(msg: Any) : Future[Any] = fooAc.ask("foo")
  val x = Await.result(ask2("foo"), Duration.Inf)
  println(x)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM