Scala trait Haskell 类型类和 C++0x 概念有什么区别?
就像下面这个例子中 Observer 声明一个抽象成员 receiveUpdate Observer 实际上是一个“匿名”类型或结构类型。
package observer
trait Subject {
type Observer = { def receiveUpdate(subject: Any) }
private var observers = List[Observer]()
def addObserver(observer:Observer) = observers ::= observer
def notifyObservers = observers foreach (_.receiveUpdate(this))
}