Why does TypeTag not work for return types?
问题 It seems that TypeTags only work for type parameters that are used in the parameters of the called method, and not the return type: scala> :paste // Entering paste mode (ctrl-D to finish) import scala.reflect.runtime.universe._ object Test { def withParam[T: TypeTag](v: T): T = { println(typeOf[T]) 0.asInstanceOf[T] } def justReturn[T: TypeTag](): T = { println(typeOf[T]) 0.asInstanceOf[T] } } // Exiting paste mode, now interpreting. import scala.reflect.runtime.universe._ defined module Test