从 typeOf[List[Int]] 获取 typeOf[Int]
Get typeOf[Int] from typeOf[List[Int]]
我想做的是:从tpe
得到typeOf[Int]
。它应该推广到 Int
.
以外的任何类型
val tpe = typeOf[List[Int]]
val ??? = typeOf[Int]
谢谢。
尝试
import scala.reflect.runtime.universe._
val tpe = typeOf[List[Int]]
tpe.typeArgs.head == typeOf[Int] // true
或
import scala.reflect.runtime.universe._
type T = List[Int]
val tpe = typeOf[T]
tpe.dealias.typeArgs.head == typeOf[Int] // true
我想做的是:从tpe
得到typeOf[Int]
。它应该推广到 Int
.
val tpe = typeOf[List[Int]]
val ??? = typeOf[Int]
谢谢。
尝试
import scala.reflect.runtime.universe._
val tpe = typeOf[List[Int]]
tpe.typeArgs.head == typeOf[Int] // true
或
import scala.reflect.runtime.universe._
type T = List[Int]
val tpe = typeOf[T]
tpe.dealias.typeArgs.head == typeOf[Int] // true