In Scala, the main class constructor does not have an explicit body, but is implicitly defined from the body of the class. How, then, to distinguish between fields and local values ββ(i.e., values ββlocal to the constructor method)?
For example, take the following code snippet, a modified form of some sample code from "Programming in Scala":
class R(n: Int, d: Int) { private val g = myfunc val x = n / g val y = d / g }
I understand that this will create a class with three fields: private "g" and publicly available "x" and "y". However, the value of g is used only to calculate the fields x and y and does not matter outside the scope of the constructor.
So, in this (supposedly artificial) example, how are you going to define local values ββfor this constructor?
scala scala-primary-constructor
skaffman Jul 13 '09 at 10:17 2009-07-13 10:17
source share