Reputation: 2661
I am new to Scala and I have a case class "Lr". I need to print all the attribute names as header delimited by tab like:
some1_ID some2_ID
But I am getting ans:
value some1_ID value some2_ID
May I get help on how to modify my code to get the right ans?
package com.......
case class Lr (
some1_ID : Option[String],
some2_ID : Option[String]
)
object EchoLr {
def classAccessors[T: TypeTag]: String = typeOf[T].members.collect {
case m: MethodSymbol if m.isCaseAccessor => m
}.mkString("\t")
def main( args:Array[String] ):Unit = {
val testLR = Lr(Option("something1"),Option("something2"))
println(classAccessors[Lr])
}
}
I was following :
Get field names list from case class
Upvotes: 2
Views: 3538
Reputation: 20541
Replace
case m: MethodSymbol if m.isCaseAccessor => m
by
case m: MethodSymbol if m.isCaseAccessor => m.name
Upvotes: 2