Scala 构造函数结果类型不是<;:&书信电报;具有类型参数的类上的类类型

Scala 构造函数结果类型不是<;:&书信电报;具有类型参数的类上的类类型,scala,reflection,Scala,Reflection,根据使用typeSignatureIn,而不仅仅是typeSignature,以获得能够说明符号所有者的确切类型的类型信息。false在我看来是正确的结果类型,这可能是关键线索。我从ClassWithTypeParam[String]获得了构造函数,并希望构造函数返回该类型。显然不是。那么,我如何专门为ClassWithTypeParam[String]获取构造函数呢?decl(…).typeSignatureIn(classType)@EugeneBurmako哦,这很有效!谢谢如果你想要+1

根据
使用typeSignatureIn,而不仅仅是typeSignature,以获得能够说明符号所有者的确切类型的类型信息。

false
在我看来是正确的<代码>结果类型,这可能是关键线索。我从
ClassWithTypeParam[String]
获得了构造函数,并希望构造函数返回该类型。显然不是。那么,我如何专门为
ClassWithTypeParam[String]
获取构造函数呢?decl(…).typeSignatureIn(classType)@EugeneBurmako哦,这很有效!谢谢如果你想要+15荣耀,就把它作为答案贴出来。您能简要解释一下“站点”的完整含义吗?因为在
typeSignatureIn
的文档中使用了这个词。我认为它指的是所有者的确切类型。站点可能意味着获得签名的符号的定义站点。
// Scala 2.11.1
case class ClassWithTypeParam[A](x: Int)

def main(args: Array[String]) {
  val classType = weakTypeOf[ClassWithTypeParam[String]]
  val constructorType = classType.decl(termNames.CONSTRUCTOR).asMethod.typeSignature
  val MethodType(constructorParams, resultType) = constructorType
  println(s"$classType\n$constructorType\n$constructorParams\n$resultType\n")
  println(resultType <:< classType)  // should print "true"
}
ClassWithTypeParam[String]
(x: scala.Int)ClassWithTypeParam[A]
List(value x)
ClassWithTypeParam[A]

false