How can I get the simple class name including generic using TypeTag? I think that the method signature should be like:
def getClassName[A: TypeTag](a: A): String
getClassName(Map("a" -> 123)) should return Map[String,Int].
Things I've tried:
def getClassName[A: TypeTag](a: A): String = {
typeOf[A].typeSymbol.name.toString
}
scala> getClassName(Map("a" -> 123))
res1: String = Map
def getClassName[A: TypeTag](a: A): String = {
typeOf[A].typeSymbol.toString
}
scala> getClassName(Map("a" -> 123))
res1: String = trait Map
def getClassName[A: TypeTag](a: A): String = {
typeOf[A].toString
}
scala> getClassName(Map("a" -> 123))
res1: String = scala.collection.immutable.Map[String,Int] // It knows the full type!
def getClassName[A: TypeTag](a: A): String = {
typeOf[A].typeSymbol.fullName
}
scala> getClassName(Map("a" -> 123))
res1: String = scala.collection.immutable.Map