【发布时间】:2011-08-05 08:33:40
【问题描述】:
在下面有什么方法可以选择使用 asJavaIterable 吗?我知道我可以拼出那个特定的函数名,但我想知道我是否可以明确地指定我想要的类型。我也很好奇为什么 asJavaIterable 没有优先于 asJavaCollection。
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]
^
【问题讨论】:
标签: scala