How to get the companion object for the class type?

I want something as flowing in scala3:

class A {}
object A {}

def companion[T](using xx): xx.Comp = ???

assert(companion[A] == A)

Not really possible unless you use something like macros, and in general, not useful at all.

Assume for a moment you get the companion object, now what? What do you do with it?
Usually, the meta-problem you are trying to solve here is better solved using a typeclass.

3 Likes