문제

I'm working on a Scala macro where I want to match the type of a Symbol to a List[T], where the T is a given Type. I have the Type object of the T type parameter already.

It's easy to get the Type object of List[_]:

  val listType = c.weakTypeOf[List[_]]

with this I can already check the typeSignature

  sourceParam.typeSignature match {
    case paramType if paramType <:< listType =>
      ....
  }

But I want to check paramType with List[T], so how do I make a Type where I take the List[_] and some Type object and make it a new Type?

도움이 되었습니까?

해결책

scala> val tpeList = typeOf[List[_]]
tpeList: reflect.runtime.universe.Type = scala.List[_]

scala> appliedType(tpeList, List(typeOf[Int]))
res0: reflect.runtime.universe.Type = scala.List[Int]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top