7
在下面的任何方式選擇使用asJavaIterable?我知道我可以拼出特定的函數名稱,但我想知道如果我可以只聲明指定我想要的類型。我也很好奇,爲什麼JavaJavaIterable不會優先於JavaJavaCollection。解決Scala中模糊的隱式轉換問題
scala> import scala.collection.JavaConversions._
import scala.collection.JavaConversions._
scala> Iterable(0,1):java.lang.Iterable[Int]
<console>:11: error: type mismatch;
found : Iterable[Int]
required: java.lang.Iterable[Int]
Note that implicit conversions are not applicable because they are ambiguous:
both method asJavaIterable in object JavaConversions of type [A](i: Iterable[A])java.lang.Iterable[A]
and method asJavaCollection in object JavaConversions of type [A](i: Iterable[A])java.util.Collection[A]
are possible conversion functions from Iterable[Int] to java.lang.Iterable[Int]
Iterable(0,1):java.lang.Iterable[Int]
^