Why does the definition of Array.map in Scala is "throw new Error()"
Posted
by Oscar Reyes
on Stack Overflow
See other posts from Stack Overflow
or by Oscar Reyes
Published on 2010-05-21T19:09:02Z
Indexed on
2010/05/21
19:10 UTC
Read the original article
Hit count: 503
The source code of map
for Array is:
override def map[B](f: A => B): Array[B] = throw new Error()
But the following works:
scala> val name : Array[String]= new Array(1)
name: Array[String] = Array(null)
scala> name(0)="Oscar"
scala> val x = name.map { ( s: String ) => s.toUpperCase }
x: Array[java.lang.String] = Array(OSCAR)
© Stack Overflow or respective owner