Ale*_*nov 2 reflection scala scala-reflect
如何解决给定的别名Type?即
import reflect.runtime.universe._
type Alias[A] = Option[Option[A]]
val tpe = typeOf[Alias[_]]
val ExistentialType(quantified, underlying) = tpe
Run Code Online (Sandbox Code Playgroud)
我如何Option[Option[_$1]]从underlying(或从tpe)获得?我知道这typeSymbol确实解决了别名,但它似乎丢失了过程中的参数:
scala> val tT = typeOf[Alias[_]].typeSymbol
tT: reflect.runtime.universe.Symbol = class Option
scala> tT.asType.toType
res3: reflect.runtime.universe.Type = Option[A]
scala> tT.asType.typeParams
res4: List[reflect.runtime.universe.Symbol] = List(type A)
Run Code Online (Sandbox Code Playgroud)