[英]Where are akka.actor.ActorRef ask / tell shortcuts ? ! defined in API?
[英]non-variable type argument akka.actor.ActorRef
這是涉及akka的代碼:
def receive = {
case idList: List[ActorRef] => idList.foreach(x => x ! Msg)
}
Sbt抱怨:
non-variable type argument akka.actor.ActorRef in type pattern List[akka.actor.ActorRef] is unchecked since it is eliminated by erasure
[warn] case idList: List[ActorRef] => idList.foreach(x => x ! Msg)
我該如何擺脫呢?
在運行時List[Whatever]
等同於List[Any]
,因此您的Actor可以確定它收到了一個列表,但不是那是ActorRef
的列表。 這是JVM問題,不是Scala或Akka的錯。
您有兩種選擇:
1)通過將ActorRef
替換為_
忽略它
case idList: List[_] => ...
2)將其包裝到數據結構中(推薦)
case class Ids(idList: List[ActorRef])
第二種選擇是讓您對照Ids進行檢查,而不必檢查列表的參數類型。
def receive = {
case Ids(idList) => idList.foreach(x => x ! Msg)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.