簡體   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