Scala types: Class A is not equal to the T where T is: type T = A
问题 I was reading the section 20.7 of the book Programming in Scala and I was wondering why while this code compiles: class Food class Fish extends Food class Grass extends Food abstract class Animal { type SuitableFood <: Food def eat(food: SuitableFood) } class Cow extends Animal { type SuitableFood = Grass override def eat(food: Grass) {} } val bessy: Animal = new Cow bessy eat (new bessy.SuitableFood) This code does not (the rest of the code is the same as before, only the last line changes):