Today I had a strange problem with case class constructors. I wanted to make the constructor private, and it seems like this is not a problem. So I tried this in one of my projects and it works. But in another project, I can call a private constructor, and it compiles. I thought this was something with my idea, so I made a separate class and compiled it using scalac. And it compiles. Here is the code:
package com.test object Main { def main(args: Array[String]) { val bar = Bar("12345") // bar.doStuff() println(bar) } } case class Bar private(foo: String){ private def doStuff():Unit = println("stuff") }
The funny thing is that if I uncomment bar.doStuff (), it will not compile. Therefore, I suppose private work in this case, but somehow does not work for the constructor. What am I doing wrong? Scalac - 2.11.8
source share