How to get constructor arguments in a method using typetags/mirrors?

前端 未结 1 1222
梦谈多话
梦谈多话 2021-01-14 07:06

For Case Class:

case class MyClass(param1: String, param2: String)

Why does this reflective method:

import scala.reflect.ru         


        
相关标签:
1条回答
  • 2021-01-14 07:38
    getSettings(MyClass)
    

    MyClass is the companion object of class MyClass. It has no constructor parameters.

    You should rewrite your code like this:

    def getSettings[T]()(implicit tag: TypeTag[T]) {
      ...
    }
    
    scala> getSettings[MyClass]
    List((param1,String), (param2,String))
    
    0 讨论(0)
提交回复
热议问题