title: how to display value of case class in scala
body: <pre><code>case class Keyword(id: Int = 0, words: String)
  
  val my= Keyword(123, "hello")
  
  val fields: Array[Field] = my.getClass.getDeclaredFields
  
  for (i &lt;- fields.indices) {
  
    println(fields(i).getName +":"+ my.productElement(i))
  
  }
  </code></pre>
  
  <p>id:123</p>
  
  <p>title:keyword's title</p>
  
  <p>it's ok. </p>
  
  <pre><code>def outputCaseClass[A](obj:A){
  
    val fields: Array[Field] = obj.getClass.getDeclaredFields
  
    for (i &lt;- fields.indices) {
  
      println(fields(i).getName +":"+ obj.productElement(i))
  
    }
  }
  
  outputCaseClass(my)
  </code></pre>
  
  <p>it's wrong</p>