case class copy 'method' with superclass

后端 未结 7 2011
误落风尘
误落风尘 2020-12-05 07:16

I want to do something like this:

sealed abstract class Base(val myparam:String)

case class Foo(override val mypar         


        
7条回答
  •  悲哀的现实
    2020-12-05 07:31

    Its an old problem, with an old solution,

    https://code.google.com/p/scala-scales/wiki/VirtualConstructorPreSIP

    made before the case class copy method existed.

    So in reference to this problem each case class MUST be a leaf node anyway, so define the copy and a MyType / thisType plus the newThis function and you are set, each case class fixes the type. If you want to widen the tree/newThis function and use default parameters you'll have to change the name.

    as an aside - I've been waiting for compiler plugin magic to improve before implementing this but type macros may be the magic juice. Search in the lists for Kevin's AutoProxy for a more detailed explanation of why my code never went anywhere

提交回复
热议问题