Scala types: Class A is not equal to the T where T is: type T = A

前端 未结 3 729
一生所求
一生所求 2021-01-19 05:13

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 Gr         


        
3条回答
  •  时光取名叫无心
    2021-01-19 05:48

    I believe bessy eat (new bessy.SuitableFood) compiling is a bug (which was fixed in 2.11). Because another subtype of Animal could have a SuitableFood for which new makes no sense, e.g. type SuitableFood = Food or even type SuitableFood = Food with Int (Food with Int is a perfectly nice subtype of Food!).

提交回复
热议问题