I have been able to get a List of attributes for a case class using scala with Reflection.
import scala.reflect.runtime.universe._
def classAccessors[T: TypeTag]: List[MethodSymbol] = typeOf[T].members.collect {
case m: MethodSymbol if m.isCaseAccessor => m
}.toList
case class Z(a1: String, b1: String, id: Integer)
val z = classAccessors[Z]
val res1 = z.map(x => if(x.equals("value id")) "xxx" else x)
However, the
.equals
does not work, but gives no error -> so I am missing something and I can't google it. Must be something basic.
.replace
does not work, how would that go?.How do I just get a normal List for processing? I note a
List[Object]
. Did not find anything either in that regard. Mmm. Can someone give an example of not using Reflection?