我有这样的事情:
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)
}
}
我是否有办法使用列表traitnames
中的名称来混合类中的特征,比如Colors
- 就像main method
这里所示 - 而不是手动编写mixin语句?
我可以在某些特征周围使用注释来稍后调用它们来进行混音吗?