scala> val a = Set(1,2,3) a: scala.collection.immutable.Set[Int] = Set(1, 2, 3) scala> a.getClass.getName res0: java.lang.String = scala.collection.immutable.Set$Set3
(Yes, this is indeed an instance of the inner class called Set3 - it is a set specialized for 3 elements. If you make it a little big, it will be a HashTrieSet .)
Edit: @pst also indicated that the [Int] type information was erased; this is how JVM generics work. However, REPL keeps track of it since the compiler still knows the type. If you want to get a type that the compiler knows, you can
def manifester[A: ClassManifest](a: A) = implicitly[ClassManifest[A]]
and then you get something whose toString matches what the REPL reports. Between the two of them, you will get as much type information as there should be. Of course, since REPL already does this for you, you usually don't need to use this. But if for some reason you want, erasable types are available from .typeArguments from the manifest.
source share