Yes and no – yes, you can get that sort of info; no, it’s mostly not Scala.
For this sort of thing, the information is all coming from the JVM, so you generally just drop down to the underlying Java data structure, Class.
If you know explicitly what type you are looking for at code time (less commonly useful), you can get that by simply saying classOf[MyClass]
.
If you need it as a parameter, you use the ClassTag
implicit to fetch it (not tested, and it’s early in the morning, so please forgive if there is a mistake):
def thingy[T](t: T)(implicit tag: ClassTag[T]) = {
val classOfT: Class[_] = tag.runtimeClass
}
Either way, the Class
is basically the main underlying data structure at the JVM level, and has more or less all of the available runtime information. I suspect the Clojure type-reflect
is mostly using that under the hood.
Note that there is also a TypeTag
concept in Scala, found in an external library. That’s a bit more complicated to use, but provides access to the compile-time type information, which is significantly richer than the erased runtime information. It doesn’t sound like you need that level of power, in which case I recommend not worrying about it, but it is sometimes the right tool for the job.