Is it possible to determine type of Seq[A]
in Scala 2.11.2?
For example:
val fruit = List("apples", "oranges", "pears")
val nums = List(1, 2, 3, 4)
I want to print type of Seq something like this:
scala> def printType[A](xs: Seq[A]): Unit = xs match {
| case x: List[String] => println("String")
| case y: List[Int] => println("Int")
| }
<console>:8: warning: non-variable type argument String in type pattern List[Str
ing] (the underlying of List[String]) is unchecked since it is eliminated by era
sure
case x: List[String] => println("String")
^
<console>:9: warning: non-variable type argument Int in type pattern List[Int] (
the underlying of List[Int]) is unchecked since it is eliminated by erasure
case y: List[Int] => println("Int")
^
<console>:9: warning: unreachable code
case y: List[Int] => println("Int")
^
printType: [A](xs: Seq[A])Unit
p.s. I'm new in Scala.
UPDATE:
Is there solution without using Reflection API?