I have something like this:
trait Color {
def myname: String = ""
}
trait White extends Color {
override def myname = super.myname + " white "
}
trait Green extends Color {
override def myname = super.myname + " green "
}
trait Yellow extends Color {
override def myname = super.myname + " yellow "
}
object TestA {
val traitnames: List[String] = List("White", "Green", "Yellow")
def main(args: Array[String]) {
class Colors extends White with Green with Yellow
val c = new Colors
println(c.myname)
}
}
Is there a way how I can use the names from the List traitnames
to mix traits in a class, let say, Colors
- like is shown in the main method
here - instead of writing the mixin statement manually?
Aucun commentaire:
Enregistrer un commentaire