當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Scala Varargs.apply用法及代碼示例

apply 方法(或屬性)屬於 scala.quoted.Varargs 對象(object),其相關用法說明如下。

用法:

def apply[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]]

將此表達式序列提升為序列的表達式

將表達式序列 Seq(e1, e2, ...) 其中 ei: Expr[T] 轉換為等效於 '{ Seq($e1, $e2, ...) } 的表達式,鍵入為 Expr[Seq[T]]

用法:

package scala.quoted
trait Snippet0 { self: quoted.Varargs.type =>
  def f(using Quotes) = {
  import quotes.reflect.*
  '{ List(${Varargs(List('{1}, '{2}, '{3}))}: _*) } // equivalent to '{ List(1, 2, 3) }
  }
}

源碼:

Varargs.scala

相關用法


注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 Varargs.apply。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。