mardi 10 avril 2018

Can I invoke case class copy method with dynamic parameter without explicit reflection?

The problem is that I have some independent case classes with different fields. I wanted to write a method that returns instance of the case class of given type with one of parameters changed.

def updateParam[C : ClassTag](c: C, paramName: String, paramValue: Any): C = ...

I took advantage of this answer, but it involves the use of reflection mechanism which is not so beautiful. Is there a possibility to avoid using reflection or maybe at least hide it under the hood of some library?





Aucun commentaire:

Enregistrer un commentaire