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)
Written by Eugene Ryzhikov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Scala
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#