【发布时间】:2011-05-09 07:05:46
【问题描述】:
以下内容无法编译。我需要先投射该人吗?
object People {
def all = List(
new Person("Jack", 33),
new Person("John", 31) with Authority,
new Person("Jill", 21),
new Person("Mark", 43)
)
}
class Person(val name: String, val age: Int)
trait Authority {
def giveOrder {
println("do your work!")
}
}
object Runner {
def main(args:List[String]) {
val boss = People.all.find { _.isInstanceOf [Authority] }.get
boss.giveOrder // This line doesnt compile
}
}
【问题讨论】:
-
请添加编译器错误。
Boss不见了。
标签: scala filter type-inference scala-collections