Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Scala';有两种类型稍有不同的copyToArray方法吗?_Scala_Scala Collections - Fatal编程技术网

为什么Scala';有两种类型稍有不同的copyToArray方法吗?

为什么Scala';有两种类型稍有不同的copyToArray方法吗?,scala,scala-collections,Scala,Scala Collections,我正在学习收藏,我在书中注意到了这两种方法。第一个有什么意义?第二个似乎包括它 copyToArray (xs: Array[A], start: Int, len: Int): Unit copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit 这似乎是scaladoc的人工制品 $ scala29 Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bi

我正在学习收藏,我在书中注意到了这两种方法。第一个有什么意义?第二个似乎包括它

copyToArray        (xs: Array[A], start: Int, len: Int): Unit
copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit

这似乎是scaladoc的人工制品

$ scala29
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val c = List(1,2,3)
c: List[Int] = List(1, 2, 3)

scala> c.copyToArray

def copyToArray[B >: A](xs: Array[B]): Unit                         
def copyToArray[B >: A](xs: Array[B], start: Int): Unit             
def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit  

第二个包含第一个是正确的。然而,第一个事实上并不存在。如果您仔细查看文档,您将看到单词
[用例]

abstract def copyToArray(xs: Array[A], start: Int, len: Int): Unit
[use case] Copies elements of this collection to an array.
Scala API中的
[用例]
显示了签名的简化形式。这使得“典型”的使用方式对于新的Scala程序员来说并不可怕,否则他们可能会被疯狂的类型签名弄糊涂

您在许多其他方法中也看到了同样的情况,包括
map
(其中
CanBuildFrom
内容被隐藏):

要阅读Martin Odersky讨论该问题的旧帖子,请参阅

abstract def map[B](f: (A) ⇒ B): CC[B]
[use case] Builds a new collection by applying a function to all elements of this collection.

def map[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[Traversable[A], B, That]): That
Builds a new collection by applying a function to all elements of this collection.