samedi 7 mai 2022

Iterate over the fields of an object

I have a singleton objet with 100 different case classes. For example:

object Foo {

case class Bar1 {
...
}

... 

case class Bar100 {
...
}
}

I would like to be able to iterate over each of the case class. Something like getting all the case classes in a Seq and then being able to map over it. (map with a polymorphic function for example)

Is it possible using reflection? If yes how? And what are the drawbacks of using reflection here over hard coding a sequence with all the case classes.





Aucun commentaire:

Enregistrer un commentaire