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.
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.
The type of the expression is known statically at compile time.
To access it at runtime, you could use a
TypeTag
as in the other answer, or a trivial macro:The REPL also just reports the type assigned to an expression tree by the compiler.
Perhaps TypeTag is what you are looking for?
And just to demonstrate that it yields the static type of the expression rather than the dynamic type of the object: