Array 从哪里获取它的 toList 方法
通过搜索,我了解到将数组转换为列表的方式(或者,一种方式)是这样的:
val l = Array(1, 2, 3).toList
但我不仅在数组的 API 文档中找不到 toList 方法,而且在任何似乎是 Array 的祖先或继承特征。
使用较新的 2.9 API 文档,我看到 toList 存在于这些东西中:
ImmutableMapAdaptor ImmutableSetAdaptor IntMap List ListBuffer LongMap
MutableList Option ParIterableLike PriorityQueue Stack StackProxy
StreamIterator SynchronizedSet SynchronizedStack TraversableForwarder
TraversableOnce TraversableOnceMethods TraversableProxyLike
但我无法理解 toList 如何从其中之一获取成为数组的一部分。谁能解释一下吗?
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
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.
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
But I can't understand how toList gets from one of these to be part of Array. Can anyone explain this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 froms.c.m.ArrayOps
, which arrays acquire via implicit conversions in scala.Predef. Look for implicit methods whose names end withArrayOps
and you'll see where the magic comes from.