Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Scala equivalent of Java's ClassName.class?

Tags:

scala

People also ask

What is classOf in Scala?

A classOf[T] is a value of type Class[T] . In other words, classOf[T]: Class[T] . For example: scala> val strClass = classOf[String] strClass: Class[String] = class java. lang. String scala> :t strClass Class[String]

What is the classname of a class Java?

It's just the name of the class.

What is object in Scala?

In Scala, an object is a named instance with members such as fields and methods. An object and a class that have the same name and which are defined in the same source file are known as companions.

What is classname this in Java?

The Classname. this syntax is used to refer to an outer class instance when you are using nested classes; see Using "this" with class name for more details. However this. Classname is a compilation error ... unless you have declared an instance (or static) field with the name Classname .


There is a method classOf in scala.Predef that retrieves the runtime representation of a class type.

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

scala> val s = "hello world"
s: String = hello world

scala> s.getClass
res0: Class[_ <: String] = class java.lang.String