1
在下面的例子中,我不能隱瞞update
從公開曝光:不可能讓內部對象的方法私立外
trait Order {
sealed trait EntryOption {
private[Order] def update(e: EntryOption): Unit
}
private case object EmptyEntry extends EntryOption {
def update(e: EntryOption) =()
}
trait Entry extends EntryOption
def test(a: Entry, b: EntryOption): Unit = a.update(b)
}
它失敗"error: object creation impossible, since method $line12$$read$Order$^date in trait EntryOption of type (e: Order.this.EntryOption)Unit is not defined
「–編譯不管這應該是(?編譯器的bug),我嘗試沒有成功如下:
- 另外,還要
update
在EmptyEntry
private[Order]
- 讓它
protected
–此休息方法test
的目標是有EntryOption
的update
無法訪問外部Order
。
編輯
如果我試探着改變trait Order
到object Order
彙編,顯示潛在的編譯器錯誤?
應該在EntryOption中更新受保護而不是私人? – david
@david然後'test'方法無法訪問它 –