下面的代码将不能编译,为什么不斯卡拉与泛型类的情况下密封延伸特质
class FruitProcessor[T <: Fruit] {
def process(fruit: T) = {
// Do something with fruit
}
}
class FruitBlender[T <: Fruit] {
val fruitProcessor = new FruitProcessor[T]
def blend(fruit: T) = {
fruit match {
case b: Banana => fruitProcessor.process(b)
case a: Apple => fruitProcessor.process(a)
}
}
}
sealed trait Fruit
case class Banana(id: String) extends Fruit
case class Apple(id: String) extends Fruit
的编译错误是沿着线的我不明白原因“发现香蕉,需要T”
我在这里做错了什么?
放下'T',并将其替换为'Fruit'。 – Reactormonk