How can I easily get a Scala case class's name?

前端 未结 6 1433
刺人心
刺人心 2021-01-31 13:32

Given:

case class FirstCC {
  def name: String = ... // something that will give \"FirstCC\"
}
case class SecondCC extends FirstCC
val one = FirstCC()
val two =          


        
6条回答
  •  春和景丽
    2021-01-31 14:26

    class Example {
      private def className[A](a: A)(implicit m: Manifest[A]) = m.toString
      override def toString = className(this)
    }
    

提交回复
热议问题