我有这样的事情:
trait AO extends A {
private var link: String = "AO"
//...
}
trait AR extends A {
private var link: String = "AR"
//...
}
object AO extends AO with Atr {
atr += link
}
object AR extends AR with Atr {
atr += link
}
trait Atr {
import scala.collection.mutable._
val atr: ListBuffer[String] = ListBuffer()
def echo() = {
for(f <- atr) println("attribute: " + f)
}
}
object TestF {
def main(args: Array[String]) {
AR.echo //not what I want!
AO.echo //not what I want!
echo() //doesn't show nothing...
}
}
我如何在ListBuffer中添加这些属性,比如atr
,并像TestF的第三行一样一次性读取它们?