Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supplying "Class" type as a parameter to a method in Scala

Tags:

scala

I am exploring Scala by rewriting some of my Java code with it. In one of the Java method, I need to pass a class type as a parameter:

public void setType(Class<T> type)

In Java, I could do it by:

someobj.setType( MyClass.class )

But in Scala, I can't seem to call "MyClass.class". I am wondering how I can pass the parameter in Scala?

like image 727
defoo Avatar asked Nov 14 '25 16:11

defoo


1 Answers

You're after classOf[MyClass].

like image 182
Paul Butcher Avatar answered Nov 17 '25 08:11

Paul Butcher