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

前端 未结 3 2321
一整个雨季
一整个雨季 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 09:55

    I brought it back shortly after martin said we could do it. It doesn't work right yet, but to the extent that it does, it's behind -Xexperimental in trunk builds.

    scala> case class Foo[T, U](x1: T, x2: U)
    defined class Foo
    
    scala> Foo(List("a"), "b")
    res0: Foo[List[java.lang.String],java.lang.String] = Foo(List(a),b)
    
    scala> res0.isInstanceOf[Product2[_,_]]
    res1: Boolean = true
    

提交回复
热议问题