I want to write class whose constructor takes two parameters, but the arguments are not actually members of the class. e.g.
class P(V1:Int, V2:Int) {
val set = Set(V1, V2)
}
Having constructed the ‘set’, I don’t actually care about V1 and V2. Is there a way of expressing this in Scala ?
Well, exactly like that. If the constructor arguments are not tagged with
valorvar, nor the class is acase class, then they’ll be kept allocated if used inside methods (orlazy val, I suppose). If used just in the constructor, they won’t be allocated with the object, not even as private fields.