rbzlmq
Last Updated: February 25, 2016
·
1.954K
· eugener
1de60d98bb69f4a0e2bbad6cd4726e9f

Scala case class "reflection"

Case classes automatically mix in the Product trait, providing untyped, indexed access to the fields without any reflection:

case class Person(name: String, age: Int)

val p = Person("Eugene", 45)
val name = p.productElement(0) // name = "Eugene": Any
val age = p.productElement(1) // age = 45: Any
val fields = p.productIterator.toList // fields = List[Any]("Eugene", 45)
Say Thanks
Respond