[英]Scala Array functions in Scala REPL
I tried to create an array in scala.我试图在 scala 中创建一个数组。
In scala repl when i put dot and press tab i could see only few function available.在 scala repl 中,当我放点并按 Tab 时,我只能看到很少的 function 可用。
scala> val d = Array(1,2,3,4,5)
d: Array[Int] = Array(1, 2, 3, 4, 5)
scala> d.
apply asInstanceOf clone isInstanceOf length toString update
But i was able to run sum, head,tail etc on Array although scala repl didn't show them.但是我能够在 Array 上运行 sum、head、tail 等,尽管 scala repl 没有显示它们。
I couldn't understand why functions such as head, tail etc were not shown by scala repl.我不明白为什么 scala repl 没有显示头部、尾部等功能。
Because Array
doesn't actually have those methods.因为Array
实际上没有这些方法。 They are defined on either ArrayOps
or ArraySeq
.它们在ArrayOps
或ArraySeq
上定义。 There are implicit conversions that allow you invoke those methods directly as if they were defined on array, but what really goes on when you do array.sum
is something like ArraySeq.make(array).sum
有一些隐式转换允许您直接调用这些方法,就好像它们是在数组上定义的一样,但是当您执行array.sum
时真正发生的事情类似于ArraySeq.make(array).sum
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.