[英]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
作为构造函数参数传递。
在您的示例中, ::
是类名, head
和this
是构造函数参数。
(有关构造函数的更多信息,请参阅https://docs.scala-lang.org/tour/classes.html 。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.