1
votes

With reference to the official Scala Documentation: case-classes.html
"Case class constructor parameters are public val fields by default"

However, the decompilation of .scala

case class A(i: Int)

shows the below of Java code

private final int i; // private, not public
public int i(){ return i; }

Does the statement in case-classes.html mean:
"Case class constructor parameters are private val fields by default."
However, an automatically generated getter makes it public.

1
What the Scala language calls a "field" isn't the same thing JVM (and Java) calls a "field".Alexey Romanov

1 Answers

1
votes

Yes, constructor parameters for case classes are public vals from a language perspective. However a val is immutable, so it must be implemented as a private value in the class with a public getter but no setter.