【发布时间】:2011-02-13 04:30:01
【问题描述】:
如何编写从Array[_] 到List[_] 类型的隐式转换?我尝试了以下方法,但似乎不起作用。
scala> implicit def arrayToList[A : ClassManifest](a: Array[A]): List[A] = a.toList
<console>:5: error: type mismatch;
found : Array[A]
required: ?{val toList: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method arrayToList in object $iw of type [A](a: Array[A])(implicit evidence$1: ClassManifest[A])List[A]
and method genericArrayOps in object Predef of type [T](xs: Array[T])scala.collection.mutable.ArrayOps[T]
are possible conversion functions from Array[A] to ?{val toList: ?}
implicit def arrayToList[A : ClassManifest](a: Array[A]): List[A] = a.toList
^
【问题讨论】: