开发者

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

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 Priori开发者_StackOverflowtyQueue 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜