In Scala, how do I get the *name* of an `object` (not an instance of a class)?

前端 未结 4 1946
后悔当初
后悔当初 2020-12-25 14:07

In Scala, I can declare an object like so:

class Thing

object Thingy extends Thing

How would I get \"Thingy\" (the name of th

4条回答
  •  佛祖请我去吃肉
    2020-12-25 14:48

    I don't know which way is the proper way, but this could be achieved by Scala reflection:

    implicitly[TypeTag[Thingy.type]].tpe.termSymbol.name.toString
    

提交回复
热议问题