Why do case classes extend only Product and not Product1, Product2, …, ProductN?

前端 未结 3 2324
一整个雨季
一整个雨季 2021-02-19 08:58

after I learned that case classes extend Product, I wondered why they do not extend ProductN. E.g., given a code like:

case class Foo(a: Int)

I

3条回答
  •  天命终不由人
    2021-02-19 10:02

    Consider this:

    case class X(n: Int)
    case class Y(x: String, y: Int) extends X(y)
    

    If case classes extended ProductN, then that would extend both Product1 and Product2, but the type parameter changes, so there are two different overloads for _1. This is just one problem -- I bet there are others.

    Now, case class inheriting case class has been deprecated, and Martin Odersky is now considering making them inherit ProductN. AFAIK, is has not been done yet, but the obstacle has been removed.

提交回复
热议问题