【问题标题】:Where is List("String") described in API?API 中描述的 List("String") 在哪里?
【发布时间】:2014-05-31 00:07:33
【问题描述】:

当我创建一个新的字符串列表时:val lines = List("this is a test" , "a new test") 这个调用方法应用:override def apply[A](xs: A*): List[A] = xs.toList 在这种情况下返回一个 List[String]

阅读 Scala 文档以获取列表:http://www.scala-lang.org/api/current/#scala.collection.immutable.List

def apply(n: Int): A

Selects an element by its index in the sequence. 

为什么会有所不同? API中是否有部分可以查看申请创建新列表的描述?

【问题讨论】:

    标签: scala


    【解决方案1】:

    您将 List object 的 apply 与 List class 的 apply 搞混了。

    第一个创建列表(注意顶部的大 O,它代表一个对象):

    返回的类实例 List 有它自己的 apply 方法:

    您可以通过单击那个大字母在classobject scaladoc 之间切换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-27
      • 2013-06-26
      • 2019-12-16
      • 2020-08-09
      相关资源
      最近更新 更多