Implicit conversion from array to list

How to write an implicit conversion from Array[_]to List[_]type? I tried the following, but it does not work.

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
                                                                           ^
+3
source share
2 answers
implicit def arrayToList[A](a: Array[A]) = a.toList

, . , genericArrayOps Predef, Array[T] -> ArrayOps[T], ArrayOps[T] .toList(): List[T]. Array[T] -> List[T], .toList[T]. . , arrayToList , , , . , - , , . Implicits .

, , , , Array List.

+6

Manifest ClassManifest , Array - , JVM .

, / , :

implicit def arrayToList[A](arr: Array[A]) = arr.toList

, ... , .toList - , , ?

+5

Source: https://habr.com/ru/post/1791782/


All Articles