How to override parameter on Scala class constructor -
is possible override 'val' type on scala constructor?
given class such this:
class gpperson (id: option[gpid], created: option[datetime], active: boolean, primaryemail: string)
i'd create constructor can this:
if (created == none) created = new datetime
in other words, if none value supplies, replace datetime instance. catch is, i'm trying avoid using companion object, , 'created' object needs 'val' (can't make 'var').
constructor parameters may have default value:
class gpperson (id: option[gpid], created: option[datetime] = some(new datetime), active: boolean, primaryemail: string) // instantiate it: new gpperson(id = some(id), active = false, primaryemail = myemail)
you might want reorder parameters optional parameters last ones, can omit parameter name:
class gpperson (id: option[gpid], active: boolean, primaryemail: string, created: option[datetime] = some(new datetime)) // instantiate it: new gpperson(some(id), false, myemail)
Comments
Post a Comment