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


Scala reflectModule.ByNameType用法及代碼示例

ByNameType 方法(或屬性)屬於quoted.Quotes.reflectModule特性(trait),其相關用法說明如下。

用法:

type ByNameType <: TypeRepr

=>T 類型的 by-name 定義的類型。

可以代表by-name參數如thunk in

package scala.quoted
trait Snippet0 { self: runtime.QuoteUnpickler & scala.quoted.runtime.QuoteMatching &    scala.quoted.Quotes =>
  val QuoteUnpickler = self
  val QuoteMatching = self
  val Quotes = self
  trait Snippet1 { self: Quotes.reflect.type /*Quotes.reflectModule*/ &    Quotes.reflectModule =>
    val reflect = self
    val reflectModule = self
    type T
    def log[T](thunk: => T): T = ???
  }
}

也可以表示無參數方法定義的返回類型,例如

package scala.quoted
trait Snippet0 { self: runtime.QuoteUnpickler & scala.quoted.runtime.QuoteMatching &    scala.quoted.Quotes =>
  val QuoteUnpickler = self
  val QuoteMatching = self
  val Quotes = self
  trait Snippet1 { self: Quotes.reflect.type /*Quotes.reflectModule*/ &    Quotes.reflectModule =>
    val reflect = self
    val reflectModule = self
    def foo: Int = ???
  }
}

源碼:

Quotes.scala

相關用法


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