tags:

views:

649

answers:

1

How do I get an instance of Class in Scala? In Java, I can do this:

Class<String> stringClass = String.class;

What would be the equivalent in Scala?

+7  A: 

There is a method classOf at the AnyRef level:

val stringClass = classOf[String]

You can use the getClass method to get the class object of an instance at runtime in the same manner as Java

oxbow_lakes
I knew the answer, of course, but I was getting tired of seeing the question repeated over and over, and couldn't find anything similar on Stack Overflow. :-)
Daniel
There was another question on this a while back, but I can't remember exactly where it was. Hopefully, this should trim off all the repeats!
Daniel Spiewak