【发布时间】:2015-10-02 23:57:03
【问题描述】:
为什么我在触发 printGenericType(new Box[Master]()) 时会出现错误,而在 new Box[Master]() 上运行 printGenericType(new Box()) 时不会出现任何错误?
object VarianceExample extends App {
new Box[Master]().printGenericType(new Box()) // ok
new Box().printGenericType(new Box[Master]()) // fail
}
class Box[T >: Tool](implicit m: Manifest[T]) {
def printGenericType(box: Box[T]) = {
println(s"Generic type is [$m] - $box")
}
}
class Master
class Tool extends Master
class Hammer extends Tool
【问题讨论】: