Case class copy() method abstraction

前端 未结 5 852
孤独总比滥情好
孤独总比滥情好 2021-01-02 02:08

I would like to know if it is possible to abstract the copy method of case classes. Basically I have something like sealed trait Op and then something like

5条回答
  •  旧巷少年郎
    2021-01-02 02:33

    1. What would be the benefit of a compiler generated copy method for case classes without any arguments? This would just return a new Foo, and not copy anything.
    2. To quote Lukas Rytz (I believe he implemented it):
    The copy methods are only generated if there is no member named"copy" in the class, directly defined or inherited.

提交回复
热议问题