3
在斯卡拉,为什么设置方法类型参数的较低类型边界不强制方法争论的“是超类型”限制?斯卡拉更低类型绑定'是方法参数的子类型'限制
object TypeBounds extends App {
class MotorVehicle
class Truck extends MotorVehicle
class Car extends MotorVehicle
class Saloon extends Car
class HatchBackSaloon extends Saloon
def lowerTypeBound[C >: Car](c: C): C = c
def upperTypeBound[C <: Car](c: C): C = c
// Works. HatchBackSaloon is a sub class of Car
println(upperTypeBound(new HatchBackSaloon()))
// as expected doesn't compile. Truck is not a subclass of Car
println(upperTypeBound(new Truck()))
// Compiles and runs, but why ? HatchBackSaloon is not a super class of Car.
println(lowerTypeBound(new HatchBackSaloon()))
}
我想这种回答我的问题[如何Java编译器为下界通配符进行类型擦除?](http://stackoverflow.com/questions/25480172/how-does-the-java-compiler-perform型擦除换下界-通配符) – tdmadeeasy