繁体   English   中英

此代码片段中紧跟在“new”关键字之后的 cons“::”运算符的含义是什么?

[英]What is the meaning of the cons "::" operator right after the "new" key word in this code snippet?

我正在学习 Scala 并在教程中看到以下定义。 有 3 个“ :: ”。 我的理解是第一个“ :: ”是class List一个方法,第三个“ :: ”是一个类名。

但我无法理解第二个“ :: ”的含义。

sealed abstract class List {
  def ::(head: Int): List = new ::(head, this)
}
case object Nil extends List
case class ::(head: Int, tail: List) extends List

new ClassName ( constructorArguments )创建类ClassName的新实例,将constructorArguments作为构造函数参数传递。

在您的示例中, ::是类名, headthis是构造函数参数。

(有关构造函数的更多信息,请参阅https://docs.scala-lang.org/tour/classes.html 。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM