Consider the following class written in Java:
class NonNegativeDouble {
private final double value;
public NonNegativeDouble(double value) {
this
In the case of case classes
it should be:
case class NonNegativeDouble(private val initValue: Double) {
val value = Math.abs(initValue)
def copy(value: Double = this.value) = NonNegativeDouble(value)
}
The implementation of copy
is required to prevent the sintesized version of the compiler that will bind the initValue
argument.
I expect that the compiler is smart enough to not retain the «extra space» for the initValue
. I haven't verified this behaviour.