Last active
May 21, 2019 14:13
-
-
Save xuwei-k/c8487c2e9ddcd802e7d1c3bec73957bb to your computer and use it in GitHub Desktop.
getGenericParameterTypes Scala 2.13.0-RC2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object A { | |
trait B { | |
// include outer param in getGenericParameterTypes | |
case class C1(a1: Int) | |
case class C2(a1: String) | |
case class C3(a1: Array[Int]) | |
// NOT include outer | |
case class C4(a1: Option[Int]) | |
case class C5(a1: List[Int]) | |
case class C6(a1: Option[String]) | |
} | |
object D extends B | |
} | |
object Main { | |
def f[X](implicit x: reflect.ClassTag[X]): String = { | |
x.runtimeClass.getConstructors.head.getGenericParameterTypes.toList.toString | |
} | |
def main(args: Array[String]): Unit = { | |
println(scala.util.Properties.versionString) | |
assert(f[A.D.C1] == "List(interface A$B, int)") | |
assert(f[A.D.C2] == "List(interface A$B, class java.lang.String)") | |
assert(f[A.D.C3] == "List(interface A$B, class [I)") | |
assert(f[A.D.C4] == "List(scala.Option<java.lang.Object>)") | |
assert(f[A.D.C5] == "List(scala.collection.immutable.List<java.lang.Object>)") | |
assert(f[A.D.C6] == "List(scala.Option<java.lang.String>)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment