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)
val m = Meter(10) // constructor Meter in class Meter cannot be accessed...
Is there a way to use a case class with a private constructor but keep the generated apply-method in the companion public?
I am aware that there is no difference (in my example) between the two options:
val m1 = new Meter(10)
val m2 = Meter(10)
but I want to forbid the first option.
-- edit --
Surprisingly the following works (but is not really what i want):
val x = Meter
val m3 = x(10) // m3 : Meter = Meter(10)
val m2 = Meter(10)
does not give any error] – Goethitecase class Meter private (m: Int)
that causes the error, when declared as top level object (scalafiddle.net/console/eb6fdc36b281b7d5eabf33396c2683a2) but it works when declared within another object or the REPL (scalafiddle.net/console/cdc0d6e63aa8e41c89689f54970bb35f) – Goethite