Let's assume I've case classes like below:
case class Id(id: Long)
case class Department(number: Long)
case class Employee(name: String, surname: String)
Now I would like to merge these classes into new one and make the instance of that type without writing the another class:
type UberEmployee = Employee with Department with Id
val uberEmployeeInstance = new UberEmployee("Jon", "Smith", 1200, 1)
or
val uberEmployeeInstance = MagicFactory[UberEmployee]("Jon", "Smith", 1200, 1)
Is any possibility to achieve this in Scala with metaprogramming or reflection? Class composition with mixins doesn't work for me in my imaginary case.
Aucun commentaire:
Enregistrer un commentaire