Scala case class private constructor but public apply method

后端 未结 3 1213
萌比男神i
萌比男神i 2020-12-08 06:50

If I have the following case class with a private constructor and I can not access the apply-method in the companion object.

case class Meter private (m: Int         


        
3条回答
  •  醉酒成梦
    2020-12-08 07:21

    It seems the requested behavior (private constructor but public .apply) may be the way Scala 2.12 implements these.

    I came to this from the opposing angle - would like a private case class constructor also block the .apply method. Reasons here: https://github.com/akauppi/case-class-gym

    Interesting, how use cases differ.

提交回复
热议问题