我正在尝试编写以下内容:
val value: Int = 3
val tpe = typeOf(value) // This is pseudocode. What should
// actually go on this line?
q"""
type U = $tpe
val v: U = $value
"""
本质上,我需要捕获value( Int) in的类型tpe并将其分配给U. 如何做到这一点?
我正在尝试编写以下内容:
val value: Int = 3
val tpe = typeOf(value) // This is pseudocode. What should
// actually go on this line?
q"""
type U = $tpe
val v: U = $value
"""
本质上,我需要捕获value( Int) in的类型tpe并将其分配给U. 如何做到这一点?
尝试
import scala.reflect.runtime.universe._
def getType[A: TypeTag](a: A): Type = typeOf[A]
val value: Int = 3
val tpe = getType(value) // Int
相关问题:如何获得 AST 所代表的值的类型?