Why do case class companion objects extend FunctionN?

前端 未结 4 1890
陌清茗
陌清茗 2020-12-05 02:04

When you create a case class, the compiler creates a corresponding companion object with a few of the case class goodies: an apply factory method matching the p

4条回答
  •  长情又很酷
    2020-12-05 02:41

    The reason why case class companion objects implement FunctionN is that before, case classes generated a class and a factory method, not a companion object. When we added extractors to Scala it made more sense to turn the factory method into a full companion object with apply and unapply methods. But then, since the factory method did conform to FunctionN, the companion object needed to conform, too.

    [Edit] That said, it would make sense to have companion objects show as their own name, not as "function"

提交回复
热议问题