Inferred type in a Scala program
问题 The Scala REPL shows the inferred type of an expression. Is there a way to know the inferred type in a normal Scala program ? For example, val x = { //some Scala expressions } Now I want to know the actual type of x. 回答1: Perhaps TypeTag is what you are looking for? scala> import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._ scala> def typeOf[T](x:T)( implicit tag: TypeTag[T] ) = tag typeOf: [T](x: T)(implicit tag: reflect.runtime.universe.TypeTag[T])reflect.runtime