scala - Class parameter variable assignments -
i'm having difficult time understanding why varone, vartwo, , varthree getting "not found" errors: "not found: value "
// following being added list of type foo foo( varone = "stringvalue", vartwo = "stringvalue", varthree = true ) i'm defining foo as:
class foo(varone : string, vartwo : string, varthree : boolean) { } i thought in scala take class parameters , make fields of them?
i'm coming c++ background , assignments in variable constructors seem strange, that's example i'm following hinting do. might revert giving foo constructor , making assignments there, i'd understand way too.
what want case class
case class foo(varone : string, vartwo : string, varthree : boolean) this create variables provide case class goodness of equals, hashes, immutability, pattern matching
or if don't want case class:
class foo(val varone : string, val vartwo : string, val varthree : boolean) if field val, scala generate getter method it.
you can declare var, , scala generate both getter , setter.
if field doesn’t have var / val, in example, scala generates neither getter nor setter method field.
Comments
Post a Comment