[英]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.