M4ks
M4ks

Reputation: 12024

Get Class object of class with companion object

I has a class, let it be Foo. I also have a Foo companion object, like

object Foo {}

class Foo {}

In one file. At some other place of code, I need to retrieve Class object of my Foo class. However, when I do

import my.package.Foo

Foo.getClass()

returns Class object of companion object (Foo$) rather then class one. How can I retrieve the proper, class Class object?

Upvotes: 2

Views: 382

Answers (1)

sjrd
sjrd

Reputation: 22105

You can do so using classOf:

classOf[Foo]

Upvotes: 2

Related Questions