【发布时间】:2014-04-21 17:07:58
【问题描述】:
在 scala 中(或者一般来说)是否可以有一个具体的实现,然后再强制转换为更抽象的方法?例如
trait Tree {
def print(s:String) = println(s)
}
trait Leaf extends Tree {
def print(s:String) // force use of this to be defined later. Maybe I need the word override?
}
这个人为的例子展示了我以前从未真正考虑过使用的东西,即开始具体但扩展抽象。实际上,我已经构建了一个树状类结构,它可以处理大部分具体代码,直到它遇到各种叶类,此时我不想意外忘记覆盖。
【问题讨论】:
标签: scala