class constructor and member variables(fields) -
i trying declare class constructor there seems conflict syntax , declaring class members.
any suggestions how these go together?
class person (aname:string) { var name : string get() = this.name set(myname) {this.name = myname} init { this.name = aname } }
you're using setter inside setter doing set(myname) {this.name = myname}
. recursive call , not should do. instead use field
accessor this:
name: string? = null set(myname) { field = myname }
but actually, don't need this. can declare in primary constructor, name
should property of class:
class person(var name: string)
Comments
Post a Comment