ps0604 ps0604 - 3 months ago 10
Scala Question

How to convert .class in Scala

I have the following statement in Java that I need to convert to Scala:

MyClass myClass = object.method(MyClass.class);


Note that MyClass is a Java class, and object.method a Java method.

My attempt is

val myClass = object.method(MyClass.class)


however I get an error in
MyClass.class
saying
identifier expected but 'class' found
. How to convert this?

Answer

Scala equivalent of Java .class is classOf method

Try

object.method(classOf[MyClass])
Comments