如何在 Scala 中获得 Class的实例:
Class
Class<String> stringClass = String.class;
在 Scala 中等价于什么?
There is a method classOf in scala.Predef that retrieves the runtime representation of a class type.
scala.Predef
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
getClass
scala> val s = "hello world" s: String = hello world scala> s.getClass res0: Class[_ <: String] = class java.lang.String