Array 从哪里得到它的 toList 方法 [英] Where does Array get its toList method
问题描述
通过搜索,我了解将数组转换为列表的方式(或方式)如下:
Through searches, I understand the way (or, a way) to convert an Array to a List is like so:
val l = Array(1, 2, 3).toList
但我不仅在 Array 的 API 文档中找不到 toList 方法,而且在任何似乎是 Array 的祖先或继承特征的东西中也找不到它.
But not only can I not find the toList method in Array's API docs, I can't find it in anything that seems to be an ancestor or inherited trait of Array.
使用较新的 2.9 API 文档,我看到 toList 存在于这些东西中:
Using the newer 2.9 API docs, I see that toList exists in these things:
ImmutableMapAdaptor ImmutableSetAdaptor IntMap List ListBuffer LongMap
MutableList Option ParIterableLike PriorityQueue Stack StackProxy
StreamIterator SynchronizedSet SynchronizedStack TraversableForwarder
TraversableOnce TraversableOnceMethods TraversableProxyLike
但我无法理解 toList 如何从其中之一获取成为 Array 的一部分.谁能解释一下?
But I can't understand how toList gets from one of these to be part of Array. Can anyone explain this?
推荐答案
toList
和在 Java 数组中原生找不到的类似方法(包括我们以前的最爱,map、flatMap、filter 等)来自scmArrayOps
, 哪些数组通过 scala.Predef.寻找名称以 ArrayOps
结尾的隐式方法,你就会明白魔法的来源.
toList
and similar methods not natively found on Java arrays (including our old favourites, map, flatMap, filter etc.) come from s.c.m.ArrayOps
, which arrays acquire via implicit conversions in scala.Predef. Look for implicit methods whose names end with ArrayOps
and you'll see where the magic comes from.
这篇关于Array 从哪里得到它的 toList 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!