Get field names list from case class

后端 未结 6 1712
别跟我提以往
别跟我提以往 2020-11-27 03:31

I need to get only field names of case class. I\'m not interested in its values. I thought getClass.getDeclaredFields.map(_.getName) would return a list of fiel

6条回答
  •  温柔的废话
    2020-11-27 04:34

    Following Andrey Tyukin solution, to get only the list of fields in Scala 2.12:

    val fields: List[String] = classOf[Dummy].getDeclaredFields.map(_.getName).toList
    

提交回复
热议问题